【问题标题】:NGINX Load Balancing a Turn ServerNGINX 负载均衡转服务器
【发布时间】:2019-01-05 01:35:55
【问题描述】:

我正在尝试将负载均衡器放在 Turn Server 的前面以与 WebRTC 一起使用。在我的负载平衡器工作之前,我在下面的示例中使用单轮服务器。转弯服务器需要多个端口,包括一个 UDP,如下所示:

  • TCP 80
  • TCP 443
  • TCP 3478
  • TCP 3479
  • UDP 3478

我尝试在 Turn Server 前面放置一个 Amazon Elastic Load Balancer (AWS ELB),但它不支持 UDP 端口。所以我现在在所有这些端口都打开的 EC2 实例上运行 Ubuntu,并且我已经安装了 NGINX。

我已经编辑了 /etc/nginx/nginx.conf 文件并添加了一个“流”部分,其中包含每个端口的上游和服务器。但是,它似乎没有正确通过流量。

stream {
    # IPv4 Section
    upstream turn_tcp_3478 {
        server 192.168.1.100:3478;
    }
    upstream turn_tcp_3479 {
        server 192.168.1.100:3479;
    }
    upstream turn_upd_3478 {
        server 192.168.1.100:3478;
    }

    # IPv6 Section
    upstream turn_tcp_ipv6_3478{
        server [2600:myaw:esom:e:ipv6:addr:eswo:ooot]:3478;
    }
    upstream turn_tcp_ipv6_3479{
        server [2600:myaw:esom:e:ipv6:addr:eswo:ooot]:3479;
    }
    upstream turn_udp_ipv6_3478{
        server [2600:myaw:esom:e:ipv6:addr:eswo:ooot]:3478;
    }

    server {
        listen 3478; # tcp

        proxy_pass turn_tcp_3478;
    }
    server {
        listen 3479; # tcp
        proxy_pass turn_tcp_3479;
    }
    server {
        listen 3478 udp;
        proxy_pass turn_upd_3478;
    }
    server {
        listen [::]:3478;
        proxy_pass turn_tcp_ipv6_3478;
    }
    server {
        listen [::]:3479;
        proxy_pass turn_tcp_ipv6_3479;
    }
    server {
        listen [::]:3478 udp;
        proxy_pass turn_udp_ipv6_3478;
    }
}

我还在 /etc/nginx/conf.d/load-balancer.conf 中创建了一个自定义负载均衡器配置文件,并将以下内容放入其中。

upstream turn_http {
    server 192.168.1.100;
}
upstream turn_https {
    server 192.168.1.100:443;
}

upstream turn_status {
    server 192.168.1.100:8080;
}

upstream turn_ipv6_http {
    server [2600:myaw:esom:e:ipv6:addr:eswo:ooot]:80;
}
upstream turn_ipv6_https {
    server [2600:myaw:esom:e:ipv6:addr:eswo:ooot]:443;
}

server {
    listen 80; 

    location / {
        proxy_pass http://turn_http;
    }
}

server {
    listen 443 ssl;

    server_name turn.awesomedomain.com;
    ssl_certificate /etc/ssl/private/nginx.ca-bundle;
    ssl_certificate_key /etc/ssl/private/nginx.key;

    location / {
        proxy_pass https://turn_https;
    }
}

server {
    listen 8080;

    location / {
        proxy_pass http://turn_status;
    }
}

server {
    listen [::]:80; 

    location / {
        proxy_pass http://turn_ipv6_http;
    }
}

server {
    listen [::]:443 ssl;

    server_name turn.awesomedomain.com;
    ssl_certificate /etc/ssl/private/nginx.ca-bundle;
    ssl_certificate_key /etc/ssl/private/nginx.key;

    location / {
        proxy_pass https://turn_ipv6_https;
    }
}

根据自定义 load-balancer.conf 文件,http 和 https 流量似乎工作正常。

我不确定为什么我在 ngnix.conf 文件中配置的 TCP/UDP 端口没有按预期工作。

【问题讨论】:

  • 仅供参考,有不同类型的 AWS 负载均衡器。 Application Load Balancers 只支持 HTTP/HTTPS,而 Network Load Balancers 支持 TCP/UDP 流量负载均衡。

标签: nginx load-balancing elastic-load-balancer


【解决方案1】:

你的 NGINX 负载均衡器配置没问题。

我建议验证以下内容:

  1. 您的 Amazon EC2 Turn Server 实例中的安全组应具有与您的负载均衡器配置匹配的入站端口。
  2. 检查您的转向服务器上的配置文件,并确认它正在侦听的端口与您在负载平衡器上转发的端口相同。例如,您在 NGINX 配置上转发了 TCP 3479。您需要确保转向服务器正在侦听该端口。
  3. 最后,您可能还需要设置一些类似于您在 Turn Server 上设置的 IP 表。查看您的 Turn Server 的配置,看看您是否需要在负载均衡器上进行任何 iptables 或 ip6table 配置。

【讨论】:

    【解决方案2】:

    看看这个配置方法link

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-28
      • 1970-01-01
      相关资源
      最近更新 更多