Reputation: 2809
How can I increase the file descriptors limit in nginx?
There are several ways to increase file descriptors:
Edit /etc/security/limits.conf
and set nofile soft and hard limits for the nginx user.
Set $ULIMIT in /etc/default/nginx
. The nginx init.d
script set ulimit $ULIMIT https://gist.github.com/aganov/1121022#file-nginx-L43
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
Upvotes: 5
Views: 7973
Reputation: 281
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.
Upvotes: 3
Reputation: 2809
The correct way to increase the limit is by setting worker_rlimit_nofile.
Upvotes: 3