nginx报accept4( ) failed (24: Too many open files)
生产环境因为并发量突然增大,导致系统登录页面刷新、访问失败报500
查看nginx后台错误日志,发现频繁打印accept4() failed (24: Too many open files)
[yunwei@nginx ~]# tail -f /usr/local/openresty/nginx/logs/error.log 2022/11/21 08:40:36 [alert] 28808#28808: *57325374 socket() failed (24: Too many open files) while connecting to upstream, client: 172.25.100.227, server: , request: "POST /nginx/api/data/nginxDataCheck HTTP/1.1", upstream: "http://10.30.40.56:8009/data/nginxDataCheck", host: "172.25.102.126:20002" 2022/11/21 08:40:36 [crit] 28808#28808: accept4() failed (24: Too many open files) 2022/11/21 08:40:37 [alert] 28808#28808: *57325398 socket() failed (24: Too many open files) while connecting to upstream, client: 172.25.100.227, server: , request: "POST /nginx/api/data/nginxDataCheck HTTP/1.1", upstream: "http://10.30.40.56:8009/data/nginxDataCheck", host: "172.25.102.126:20002" 2022/11/21 08:40:37 [crit] 28808#28808: accept4() failed (24: Too many open files)
原因:日志里的接口也是合法的,外人是不可能访问的,大概率是nginx的系统配置没有优化,大并发访问时nginx性能堵塞
解决方法:修改vi /etc/nginx/conf/nginx.conf配置文件
#允许使用cpn数量
worker_processes 4;
events {
#进程数
worker_connections 2048;
}
#进程最大打开文件数
worker_rlimit_nofile 65536;
#重启加载nginx
nginx -s reload