大网数据广告活动
服务器运维问答

Increase max number of allowed opened files for Nginx and PHP-FPM on Ubuntu

· 52CE 我爱测

I need to increase max number of allowed opened files for Nginx 1.10 and PHP-FPM 7 on Ubuntu 16.04. According to some tutorials i changed the max number of opened files per user in /etc/security/limits.conf * soft nofile 64000 * …

问题原文

原帖链接 · user2265529 · CC BY-SA 3.0

I need to increase max number of allowed opened files for Nginx 1.10 and PHP-FPM 7 on Ubuntu 16.04. According to some tutorials i changed the max number of opened files per user in /etc/security/limits.conf

*    soft nofile 64000
*    hard nofile 68000

I also changed the max number of opened files for entire system in /etc/sysctl.conf

fs.file-max = 200500

After reloading my virtual machine i checked soft and hard limits for the user i login to the system with

igor@ubuntu:~$ ulimit -Sn
64000
igor@ubuntu:~$ ulimit -Hn
68000

As you see, the limits applied to users. My problem is that i can't change the limits for Nginx and PHP

igor@ubuntu:~$ sudo ps aux|grep nginx
root      1124  0.0  0.0  45988   980 ?        Ss   01:04   0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data  1125  0.0  0.2  46164  2372 ?        S    01:04   0:00 nginx: worker process
igor      2754  0.0  0.0   5108   848 pts/6    S+   01:14   0:00 grep --color=auto nginx
igor@ubuntu:~$ cat /proc/1124/limits
Limit                     Soft Limit           Hard Limit           Units     

.....
Max open files            1024                 4096                 files     
.....  

And the same thing for php

igor@ubuntu:~$ sudo ps aux|grep php
root      1097  0.0  2.1 118388 22496 ?        Ss   01:04   0:00 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf)
www-data  1140  0.0  0.5 118388  5532 ?        S    01:04   0:00 php-fpm: pool www
www-data  1141  0.0  0.5 118388  5532 ?        S    01:04   0:00 php-fpm: pool www
igor      2795  0.0  0.0   5108   852 pts/6    S+   01:20   0:00 grep --color=auto php
igor@ubuntu:~$ cat /proc/1097/limits
Limit                     Soft Limit           Hard Limit           Units     
.....
Max open files            1024                 4096                 files     
.....

How can i change the limits for PHP and NGINX?

已采纳解答

原帖链接 · Thomas · CC BY-SA 3.0

You need to add that configuration to the systemd unit file. Best would be to make this via a drop-in file.

mkdir /etc/systemd/system/nginx.service.d
echo "[Service]
LimitNOFILE=10000" > /etc/systemd/system/nginx.service.d/local.conf
systemctl daemon-reload
systemctl restart nginx

Then repeat that for the php7.0-fpm.service unit file.

You also can set defaults in /etc/systemd/system.conf, but it is recommended to use the drop-in files.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-08-28)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。