阿里云ECS配置nginx突破最大转发端口数量

/ 运维 / 没有评论 / 97浏览

1.注意

(1)nginx作为反向代理服务器时,转发到后端服务时,通过命令netstat -nao可知,Foreign Address外部地址为127.0.0.1:xx,所以会受到最大端口数量限制; (2)阿里云ecs默认一块主网卡(eth0),进行虚拟ip配置后,会发生无法连接其他网络服务问题,如阿里云redis得给~

2.进行配置弹性网卡,并绑定,成功后如图:

3.添加虚拟ip到eth1网卡:

 ifconfig eth1:0 172.17.194.34 netmask 255.255.240.0
ip addr add 172.17.194.34/24 dev eth1:0

ifconfig eth1:1 172.17.194.35 netmask 255.255.240.0
ip addr add 172.17.194.35/24 dev eth1:1

ifconfig eth1:2 172.17.194.36 netmask 255.255.240.0
ip addr add 172.17.194.36/24 dev eth1:2

ifconfig eth1:3 172.17.194.37 netmask 255.255.240.0
ip addr add 172.17.194.37/24 dev eth1:3

ifconfig eth1:4 172.17.194.38 netmask 255.255.240.0
ip addr add 172.17.194.38/24 dev eth1:4

ifconfig eth1:5 172.17.194.39 netmask 255.255.240.0
ip addr add 172.17.194.39/24 dev eth1:5

ifconfig eth1:6 172.17.194.40 netmask 255.255.240.0
ip addr add 172.17.194.40/24 dev eth1:6

ifconfig eth1:7 172.17.194.41 netmask 255.255.240.0
ip addr add 172.17.194.41/24 dev eth1:7

ifconfig eth1:8 172.17.194.42 netmask 255.255.240.0
ip addr add 172.17.194.42/24 dev eth1:8

修改nginx反向代理负载均衡:

upstream talkshow {
        server 127.0.0.1:18086;
        server 172.17.194.33:18086;
        server 172.17.194.34:18086;
        server 172.17.194.35:18086;
        server 172.17.194.36:18086;
        server 172.17.194.37:18086;
        server 172.17.194.38:18086;
        server 172.17.194.39:18086;
        server 172.17.194.40:18086;
        server 172.17.194.41:18086;
        server 172.17.194.42:18086;
    }
server{
        #省略 

        location api{
             proxy_pass http://talkshow/api;
        }

}