nginx报500 Internal Server Error错误

今天部署了一个nginx,web页面访问总是在报500错误(500 Internal Server Error错误),然后进入nginx的error.log里发现一直在报Too Many open files. 

2018/08/21 10:07:35 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:35 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:36 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:36 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:37 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:37 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:38 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:38 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:39 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:39 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:40 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:40 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:41 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:41 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:42 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:42 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:43 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:43 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:44 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:44 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:45 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:45 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:46 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:46 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:47 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:47 [crit] 13508#13508: accept4() failed (24: Too many open files)
2018/08/21 10:07:48 [crit] 13508#13508: accept4() failed (24: Too many open files)

我猜估计是文件打开是超出系统设置的上限了,便登录服务器查看了一下。

运行如下命令,进行查看

[root@server nginx]$ ulimit -n  
1024
[root@server nginx]$ 

发现只有1024。既然这么小,那就修改一下。

但是在修改之前我们先确认一下系统的上限是多少

[root@server nginx]# sysctl -n -e fs.file-max
13057331
[root@server nginx]# 

既然有这么多,我就不担心了,我要的其实也不多。

开始修改打开文件数量的上限,在/etc/security/limits.conf文件里,最后加上

* soft nofile 10240
* hard nofile 10240

# /etc/security/limits.conf
#
#This file sets the resource limits for the users logged in via PAM.
#It does not affect resource limits of the system services.
#
#Also note that configuration files in /etc/security/limits.d directory,
#which are read in alphabetical order, override the settings in this
#file in case the domain is the same or more specific.
#That means for example that setting a limit for wildcard domain here
#can be overriden with a wildcard setting in a config file in the
#subdirectory, but a user specific setting here can be overriden only
#with a user specific setting in the subdirectory.
#
#Each line describes a limit for a user in the form:
#
#<domain>        <type>  <item>  <value>
#
#Where:
#<domain> can be:
#        - a user name
#        - a group name, with @group syntax
#        - the wildcard *, for default entry
#        - the wildcard %, can be also used with %group syntax,
#                 for maxlogin limit
#
#<type> can have the two values:
#        - "soft" for enforcing the soft limits
#        - "hard" for enforcing hard limits
#
#<item> can be one of the following:
#        - core - limits the core file size (KB)
#        - data - max data size (KB)
#        - fsize - maximum filesize (KB)
#        - memlock - max locked-in-memory address space (KB)
#        - nofile - max number of open file descriptors
#        - rss - max resident set size (KB)
#        - stack - max stack size (KB)
#        - cpu - max CPU time (MIN)
#        - nproc - max number of processes
#        - as - address space limit (KB)
#        - maxlogins - max number of logins for this user
#        - maxsyslogins - max number of logins on the system
#        - priority - the priority to run user process with
#        - locks - max number of file locks the user can hold
#        - sigpending - max number of pending signals
#        - msgqueue - max memory used by POSIX message queues (bytes)
#        - nice - max nice priority allowed to raise to values: [-20, 19]
#        - rtprio - max realtime priority
#
#<domain>      <type>  <item>         <value>
#

#*               soft    core            0
#*               hard    rss             10000
#@student        hard    nproc           20
#@faculty        soft    nproc           20
#@faculty        hard    nproc           50
#ftp             hard    nproc           0
#@student        -       maxlogins       4

* soft nofile 10240
* hard nofile 10240
# End of file

然后退出登录,再进去查看下发现已经设置好了

[root@server nginx]$ ulimit -n  
10240
[root@server nginx]$ 

然后重启nginx,应该就好了

转载于:https://my.oschina.net/qbj/blog/1931353

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值