在Ubuntu上增加Nginx和PHP-FPM允许的最大打开文件数

我需要在Ubuntu 16.04上为Nginx 1.10和PHP-FPM 7增加允许打开的最大文件数量。 根据一些教程,我改变了/etc/security/limits.conf中每个用户打开文件的最大数量

* soft nofile 64000 * hard nofile 68000 

我还在/etc/sysctl.conf中更改了整个系统的最大打开文件数

 fs.file-max = 200500 

重新加载我的虚拟机后,我检查了用户login到系统的软硬限制

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

如您所见,限制适用于用户。 我的问题是,我不能改变Nginx和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 ..... 

和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 ..... 

我怎样才能改变PHP和NGINX的限制?

您需要将该configuration添加到systemd单元文件。 最好的办法是通过一个插件文件。

 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 

然后重复php7.0-fpm.service单元文件。

你也可以在/etc/systemd/system.conf设置默认值,但是build议使用这个drop-in文件。