How to set nginx max open files?

前端 未结 3 2065
悲&欢浪女
悲&欢浪女 2021-01-30 11:19

Though I have done the following setting, and even restarted the server:

# head /etc/security/limits.conf -n2
www-data soft nofile -1
www-data hard nofile -1
# /         


        
相关标签:
3条回答
  • 2021-01-30 12:00

    For nginx simply editing nginx.conf and setting worker_rlimit_nofile should change the limitation. I initially thought it is a self-imposed limit of nginx, but it increases limit per process:

    worker_rlimit_nofile 4096;
    

    You can test by getting a nginx process ID (from top -u nginx), then run:

    cat /proc/{PID}/limits
    

    To see the current limits

    Another way on CentOS 7 is by systemctl edit SERVICE_NAME, add the variables there:

    [Service]
    LimitNOFILE=65536
    

    save that file and reload the service.

    0 讨论(0)
  • 2021-01-30 12:06

    I found the answer in few minutes after posting this question...

    # cat /etc/default/nginx
    # Note: You may want to look at the following page before setting the ULIMIT.
    #  http://wiki.nginx.org/CoreModule#worker_rlimit_nofile
    # Set the ulimit variable if you need defaults to change.
    #  Example: ULIMIT="-n 4096"
    ULIMIT="-n 15000"
    

    /etc/security/limit.conf is used by PAM, so it shoud be nothing to do with www-data (it's nologin user).

    0 讨论(0)
  • 2021-01-30 12:10

    On CentOS (tested on 7.x):

    Create file /etc/systemd/system/nginx.service.d/override.conf with the following contents:

    [Service]
    LimitNOFILE=65536
    

    Reload systemd daemon with:

    systemctl daemon-reload
    

    Add this to Nginx config file:

    worker_rlimit_nofile 16384; (has to be smaller or equal to LimitNOFILE set above)
    

    And finally restart Nginx:

    systemctl restart nginx
    

    You can verify that it works with cat /proc/<nginx-pid>/limits.

    0 讨论(0)
提交回复
热议问题