代理WebSocket连接和短暂端口耗尽 [英] Proxying WebSocket connections and ephemeral port exhaustion
问题描述
我正在设计一个应用程序,该应用程序将使用WebSocket在发生更改时迅速通知访问者.我打算用Nginx代理连接,因此它们可以与常规HTTP部分共享相同的地址.我担心的一件事是临时端口的耗尽.过去,我发现Nginx和Node后端之间的连接数超过25000时会出现问题.我的问题是,以下配置会将限制增加到100K吗?
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.
假设该技术有效,是否可以与外部服务器一起使用?为接口分配一系列IP地址有多困难?联网不是我的强项...
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...
推荐答案
请尝试 proxy_bind .它
使到代理服务器的传出连接源于 指定的本地IP地址.参数值可以包含变量 (1.3.12).
Makes outgoing connections to a proxied server originate from the specified local IP address. Parameter value can contain variables (1.3.12).
因此,如果我们的Nginx代理服务器可以具有多个IP地址,则可以解决您的问题.例如
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;
}
变量$picked_ip
可以由在proxy_pass
之前运行的重写处理程序来计算.
The variable $picked_ip
can be computed by a rewrite handler which runs before proxy_pass
does.
这篇关于代理WebSocket连接和短暂端口耗尽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!