NGINX 负载平衡 Turn 服务器 [英] NGINX Load Balancing a Turn Server

查看:78
本文介绍了NGINX 负载平衡 Turn 服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Turn 服务器前面放置一个负载均衡器,以便与 WebRTC 一起使用.我在下面的示例中使用了一个轮流服务器,直到负载平衡器正常工作.Turn 服务器需要多个端口,包括一个 UDP,如下所列:

I am attempting to put a Load Balancer in front of a Turn Server for use with 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:

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

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

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. So I am now running Ubuntu on an EC2 Instance with all these ports open and I have installed NGINX.

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

I've edited the /etc/nginx/nginx.conf file and added a "stream" section to it with both upstream and servers for each port. 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;
    }
}

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

I have also created a custom load balancer configuration file at /etc/nginx/conf.d/load-balancer.conf and placed the following in it.

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 流量似乎工作正常.

The http and https traffic appear to be working fine based on the custom load-balancer.conf file.

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

I am unsure why the TCP/UDP Ports I have configured in the ngnix.conf file are not working as intended.

推荐答案

您对 NGINX 负载均衡器的配置很好.

Your configuration of the NGINX Load Balancer is fine.

我建议验证以下内容:

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

这篇关于NGINX 负载平衡 Turn 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆