Back

nginx - 需要设置 worker_connections 到最大才行 , 同时修改 ulimit 中的open file数量

发布时间: 2020-11-17 14:33:00

参考:https://blog.csdn.net/m0_37263637/article/details/80813881

今天发现服务器负载一高,所有访问都 50x了。

HTTP Error 502
Bad gateway
111.196.162.130/7e84fbc

17/Nov/2020:21:43:16 +0800

应用app没报错。  因为连日志都没有

tail access.log 就发现茫茫多的请求

所以,鼓捣一会儿之后,觉得是不是nginx的问题,于是才后知后觉的查看 nginx error.log

发现 connection不够。

看起来类似

2020/08/18 17:04:09 [alert] 24012#24012: 800 worker_connections are not enough
2020/08/18 17:04:09 [alert] 24012#24012: 800 worker_connections are not enough
2020/08/18 17:04:09 [alert] 24012#24012: 800 worker_connections are not enough

解决办法:

worker_processes 4;
events {
worker_connections 65535;
...
}

第二步,修改linux ulimit 

$ ulimit -a 

发现最高打开文件数量为 1024. 

open files (-n) 1024

于是需要修改文件:

/etc/security/limits.conf  ,增加下面2行:

* soft nofile 40960
* hard nofile 65536

退出ssh重进,就可以发现生效了。

Back