如何设置nginx max打开文件? [英] How to set nginx max open files?

查看:98
本文介绍了如何设置nginx max打开文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管我已经完成了以下设置,甚至重启了服务器:

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
# /sbin/sysctl fs.file-max
fs.file-max = 201558

特定进程的打开文件限制仍然是1024/4096:

The open files limitation of specific process is still 1024/4096:

# ps aux | grep nginx
root       983  0.0  0.0  85872  1348 ?        Ss   15:42   0:00 nginx: master process /usr/sbin/nginx
www-data   984  0.0  0.2  89780  6000 ?        S    15:42   0:00 nginx: worker process
www-data   985  0.0  0.2  89780  5472 ?        S    15:42   0:00 nginx: worker process
root      1247  0.0  0.0  11744   916 pts/0    S+   15:47   0:00 grep --color=auto nginx
# cat /proc/984/limits
Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        0                    unlimited            bytes
Max resident set          unlimited            unlimited            bytes
Max processes             15845                15845                processes
Max open files            1024                 4096                 files
Max locked memory         65536                65536                bytes
Max address space         unlimited            unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       15845                15845                signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0
Max realtime priority     0                    0
Max realtime timeout      unlimited            unlimited            us

我尝试了从谷歌搜索到的所有可能解决方案,但徒劳无功.我错过了什么设置?

I've tried all possible solutions from googling but in vain. What setting did I miss?

推荐答案

在CentOS上(在7.x上测试):

使用以下内容创建文件/etc/systemd/system/nginx.service.d/override.conf:

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

[Service]
LimitNOFILE=65536

使用以下命令重新加载systemd守护程序:

Reload systemd daemon with:

systemctl daemon-reload

将此添加到Nginx配置文件中:

Add this to Nginx config file:

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

最后重新启动Nginx:

And finally restart Nginx:

systemctl restart nginx

您可以验证它是否可以与cat /proc/<nginx-pid>/limits一起使用.

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

这篇关于如何设置nginx max打开文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆