错误描述
偶尔出现nignx500错误,但刷新后则显示正常。观察ningx的错误日志,发现很多的如下的错误:
2021/05/10 09:26:03 [alert] 30940#0: *1217975628 socket() failed (24: Too many open files) while connecting to upstream, client: x.x.x.x, server: localhost, request: "GET / HTTP/1.1", upstream: "http://x.x.x.x:80", host: "x.x.x.x"
查看max open files
查看nginx.pid的路径:
find / -name nginx.pid
查看nginx的 max open files:
grep 'open files' /proc/$( cat /usr/local/nginx/logs/nginx.pid )/limits
解决
修改linux打开文件句柄数,编辑vi /etc/security/limits.conf,添加
<domain> <type> <item> <value>
* soft nofile 204800
* hard nofile 204800
星号代表全局, soft为软件,hard为硬件,nofile为这里指可打开文件数。
修改nginx打开文件数, 编辑nginx.conf,添加worker_rlimit_nofile值
worker_processes 1;
worker_rlimit_nofile 65535;
events {
worker_connections 65535;
}
重启nginx后问题解决。