简体   繁体   English

NGINX负载平衡转弯服务器

[英]NGINX Load Balancing a Turn Server

I am attempting to put a Load Balancer in front of a Turn Server for use with WebRTC. 我试图将负载均衡器放在Turn Server前面,以与WebRTC一起使用。 I am using one turn server in my examples below until I get the load balancer working. 在下面的示例中,我将使用一转服务器,直到负载均衡器正常工作。 The turn server requires multiple ports including one UDP as listed below: 转向服务器需要多个端口,包括一个UDP,如下所示:

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

I have attempted to place an Amazon Elastic Load Balancer (AWS ELB) in front of the Turn Server, but it does not support the UDP port. 我试图将Amazon Elastic Load Balancer(AW​​S ELB)放置在Turn Server的前面,但是它不支持UDP端口。 So I am now running Ubuntu on an EC2 Instance with all these ports open and I have installed NGINX. 所以我现在在所有这些端口都打开的EC2实例上运行Ubuntu,并且我已经安装了NGINX。

I've edited the /etc/nginx/nginx.conf file and added a "stream" section to it with both upstream and servers for each port. 我已经编辑了/etc/nginx/nginx.conf文件,并为每个端口的上游和服务器添加了“ stream”部分。 However, it does not appear to be passing the traffic correctly. 但是,它似乎没有正确传递流量。

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;
    }
}

I have also created a custom load balancer configuration file at /etc/nginx/conf.d/load-balancer.conf and placed the following in it. 我还在/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;
    }
}

The http and https traffic appear to be working fine based on the custom load-balancer.conf file. 基于自定义load-balancer.conf文件,http和https流量似乎运行良好。

I am unsure why the TCP/UDP Ports I have configured in the ngnix.conf file are not working as intended. 我不确定为什么在ngnix.conf文件中配置的TCP / UDP端口无法正常工作。

Your configuration of the NGINX Load Balancer is fine. 您可以对NGINX负载均衡器进行配置。

I suggest verifying the following: 我建议验证以下内容:

  1. The security groups in your Amazon EC2 Turn Server instance should have matching inbound ports with your Load Balancer configuration. Amazon EC2 Turn Server实例中的安全组应具有与负载均衡器配置匹配的入站端口。
  2. Check the configuration files on your turn server and verify that the ports it is listening to are the same ports as you are forwarding on your load balancer. 检查轮流服务器上的配置文件,并验证其正在侦听的端口与您在负载均衡器上转发的端口是否相同。 For example, you have TCP 3479 being forwarded on your NGINX config. 例如,您的NGINX配置上转发了TCP 3479。 You need to make sure that the turn server is listening to that port. 您需要确保转弯服务器正在侦听该端口。
  3. Lastly, you may also need to setup some IP Tables similar to what you have setup on your Turn Server. 最后,您可能还需要设置一些IP表,类似于在Turn Server上设置的IP表。 Review your Turn Server's configuration and see if you need to do any iptables or ip6table configuration on the Load Balancer. 查看Turn Server的配置,看看是否需要在负载均衡器上进行任何iptables或ip6table配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM