2019/07/25 08:31:31 [crit] 15929#15929: accept4() failed (24: Too many open files) 2019/07/25 08:31:31 [crit] 15930#15930: accept4() failed (24: Too many open files) 2019/07/25 08:31:31 [crit] 15930#15930: accept4() failed (24: Too many open files) 2019/07/25 08:31:31 [crit] 15930#15930: accept4() failed (24: Too many open files) 2019/07/25 08:31:31 [crit] 15930#15930: accept4() failed (24: Too many open files) 2019/07/25 08:31:31 [crit] 15930#15930: accept4() failed (24: Too many open files) 2019/07/25 08:31:31 [crit] 15930#15930: accept4() failed (24: Too many open files) 2019/07/25 08:31:31 [crit] 15930#15930: accept4() failed (24: Too many open files) 2019/07/25 08:31:31 [crit] 15930#15930: accept4() failed (24: Too many open files) 2019/07/25 08:31:31 [crit] 15930#15930: accept4() failed (24: Too many open files) 2019/07/25 08:31:31 [crit] 15930#15930: accept4() failed (24: Too many open files) 2019/07/25 08:31:31 [crit] 15930#15930: accept4() failed (24: Too many open files) 2019/07/25 08:31:31 [crit] 15930#15930: accept4() failed (24: Too many open files)
注意:修改 nginx 的 max open files 有个前提,就是你已经修改好了系统的 max open files. 修改系统中的 /etc/security/limits.conf文件中 sudo vim /etc/security/limits.conf #在最后添加如下两行 * soft nofile 65535 * hard nofile 65535 这是网上搜了很多教程,但是到此还是无法解决问题 上面修改了系统的 max open files,并不代表nginx的 先查看 nginx 的 ulimits: grep 'open files' /proc/$( cat /var/run/nginx.pid )/limits
发现nginx 的 max open files 并没有变化 修改 nginx.service sudo vim /lib/systemd/system/nginx.service # (仅适用于 ubuntu) 添加如下: [Service] LimitNOFILE=65535 重启服务: sudo systemctl daemon-reload 修改 nginx.conf, 添加:以下两点 worker_rlimit_nofile 65535; # (has to be smaller or equal to LimitNOFILE set above) events { worker_connections 65535; } 重启 nginx: sudo systemctl restart nginx 然后再去查看nginx的 max open files,看看是不是我们设置的65535 grep 'open files' /proc/$( cat /var/run/nginx.pid )/limits 到此就修改nginx的max open files结束。 但是如果你已经把nginx 的max open files值改的很大了,但是还是会出现Too many open files 的错误,那说明你后端服务器处理请求的速度太慢了,或是 并发太高了。