我在反向代理模式下使用 nginx。以下是配置文件的相关部分:
server {
listen 80;
server_name ~^web.redhelper\.ru$ ;
access_log off;
location /http-bind {
proxy_pass http://localhost:7070;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
}
}
过了一段时间,我开始遇到 500 错误。我认为我达到了最大打开连接数限制。这是 munin 图表:
当我使用 netstat 时,我看到有:
1279 open connections to port 80; (including website itself that is on the same port)
of them 745 are in ESTABLISHED state and 479 in TIME_WAIT
277 ESTABLISHED connections from 127.0.0.1:[misc port] to 127.0.0.1:7070
3922 connections from 127.0.0.1:7070 to 127.0.0.1:[misc port]
of them 246 are in ESTABLISHED state and 3646 in TIME_WAIT
我认为这是 3646 个 TIME_WAIT 连接导致的。我该如何防止 nginx 占用那么多打开的连接?
这里还有一些 munin 图表,也许它们有助于更好地理解我的问题: http://munin.redhelper.ru/localdomain/localhost.localdomain/index.html