Nginx提示Error: Too many open files的解决办法

Nginx提示:Too many open files这种错误问题的原因是因为linux文件系统最大可打开文件数为1024,而你的nginx中的error.log出现大量的Too many open files,说明文件句柄不够用了所以就错误提示出来了。

如果nginx的error.log出现大量的Too many open files,说明文件句柄不够用了,这时候我们需要加大系统的文件句柄数和nginx的允许最大的连接数。

默认情况下linux文 件系统最大可打开文件数为1024,对于一个应用于生产环境下的服务器来说,这个设置太小,例如在用nginx做web服务器,当并发达到一定数量时,可以看到error.log里出现大量的“Nginx accept() failed (24: Too many open files)” 的错误。

正确设置Linux的ulimit -n的值的步骤如下:

1.先用命令ulimit -n 查看目前的值

2. vim /etc/security/limits.conf

建议把下面两项都设置为65535

* soft nofile 65535

* hard nofile 65535

(前面的*星号代表全局,针对所有的用户;nofile代表文件句柄数量;soft nofile的值不能超过hard nofile的值)

3.vim /usr/local/nginx/conf/nginx.conf

找到worker_connections ,把值调大一些,比如加个0

4.重启Linux系统

命令:shutdown -r now 表示立即重启

Nginx 的详细介绍:请点这里
Nginx 的下载地址:请点这里

相关推荐