Proxying WebSocket connections and ephemeral port exhaustion

安稳与你 提交于 2020-01-03 12:22:07

问题


I'm designing an application that make will use of WebSocket to notify visitors quickly when changes occur. I'm planning to proxy the connections with Nginx, so they can share the same address as the regular HTTP portion. One thing I'm concerned about is the exhaustion of ephemeral ports. In the past, I have noticed problems when the number of connections between Nginx and the Node backend exceeds 25000. My question is, would the following config increases the limit to 100K?

upstream backends {
    server 127.0.0.1:5000;
    server 127.0.0.2:5000;
    server 127.0.0.3:5000;
    server 127.0.0.4:5000;
}

The limit on open files will need to be raised accordingly, of course.

Assuming the technique works, can it be used with external servers? How hard is it to assign a range of IP addresses to an interface? Networking is not my forte...


回答1:


Please try proxy_bind . It

Makes outgoing connections to a proxied server originate from the specified local IP address. Parameter value can contain variables (1.3.12).

So if our nginx proxy server can have several IP addresses your problem can be resolved. e.g.

location / {
   ...
   proxy_bind $picked_ip;
   proxy_pass http://backends;
}

The variable $picked_ip can be computed by a rewrite handler which runs before proxy_pass does.



来源:https://stackoverflow.com/questions/29299132/proxying-websocket-connections-and-ephemeral-port-exhaustion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!