Nginx File descriptor limit

点点圈 提交于 2019-12-10 11:13:07

问题


How can I increase the file descriptors limit in nginx?

There are several ways to increase file descriptors:

  1. Edit /etc/security/limits.conf and set nofile soft and hard limits for the nginx user.

  2. Set $ULIMIT in /etc/default/nginx. The nginx init.d script set ulimit $ULIMIT https://gist.github.com/aganov/1121022#file-nginx-L43

  3. Set worker_rlimit_nofile in nginx.conf http://wiki.nginx.org/NginxHttpMainModule#worker_rlimit_nofile

Does setting limits in limits.conf affect nginx when started using init.d script on boot?

Do I have to use ulimit $ULIMIT in the init script or can worker_rlimit_nofile be used instead?

When using ulimit $ULIMIT in the init script, do I still need to use worker_rlimit_nofile to set limits for each worker?

Thanks


回答1:


The correct way to increase the limit is by setting worker_rlimit_nofile.




回答2:


Discussing each item:

1) /etc/security/limits.conf is only processed by pam_limits. Processes started from init.d generally do not utilize pam_limits. It's needed to set the ulimit at init level, in the service script, for example.

2) The default nginx init script doesn't have this setting (at least for Official Red Hat/CentOS packages). But changing this init script is a valid way, although it's not recommended.

3) worker_rlimit_nofile works only at process level, it's limited to the system's hard limit (ulimit -Hn). It serves to dynamically change the maximum file descriptors the nginx process can handle, which is typically defined with the system's soft limit.



来源:https://stackoverflow.com/questions/16919673/nginx-file-descriptor-limit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!