解決docker中使用nginx做負載均衡時並發過高時的一些問題
1.問題產生原因:
由於通過nginx作為負載均衡服務,在訪問並發數量達到一定量級時jmeter報錯。
nginx日志關鍵信息:accept4() failed (24: Too many open files)。
此日志引起原因是nginx進程打開文件數過多。度娘一堆類似的帖子這里引用網上的解決方式比太實用
同時出現一些502 504nginx假死問題。考慮通過增加nginx工作進程數解決。
2.解決思路:
通過配置修改ulimit -n的值,因為結合docker-compose的方式使用nginx想到對應配置
3.解決方法:
nginx:
restart: always
image: nginx
container_name: nginx
ports:
- 80:80
volumes:
- ./conf/nginx.conf:/etc/nginx/nginx.conf
- ./wwwroot:/usr/share/nginx/wwwroot
ulimits:
nproc: 65535
nofile:
soft: 65535
hard: 65535
引用:引用博文
nginx工作進程數配置方案引用