带有Nginx 1.6.2的CentOS 6.6 - 突然无法重启nginx - nginx:[emerg] open()“/ usr / share / nginx / on”失败(13:权限被拒绝)

问题描述 投票:3回答:3

这是一个新安装,其中nginx以前正常启动和停止。我相信在启用成功测试(nginx -t)的服务器块后出现此错误。然后我尝试重新启动nginx并收到此错误:

nginx: [emerg] open() "/usr/share/nginx/on" failed (13: Permission denied)

在尝试重新启动之前,文件“on”不存在。它刚刚创建并且是空的。当我重新启动php-fmp(成功)然后尝试重新启动nginx时,错误更改为:

nginx: [emerg] open() "/var/run/nginx.pid" failed (13: Permission denied) nginx: configuration file /etc/nginx/nginx.conf test failed

但是,当我运行nginx -t时,我得到:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful

我认为它可能是用户问题,但它作为nginx运行:

# ps -elf | grep nginx 5 S nginx 2774 2773 0 80 0 - 234152 skb_re 22:07 ? 00:00:00 php-fpm: pool www 5 S nginx 2775 2773 0 80 0 - 234152 skb_re 22:07 ? 00:00:00 php-fpm: pool www 5 S nginx 2776 2773 0 80 0 - 234152 skb_re 22:07 ? 00:00:00 php-fpm: pool www 5 S nginx 2777 2773 0 80 0 - 234152 skb_re 22:07 ? 00:00:00 php-fpm: pool www 5 S nginx 2778 2773 0 80 0 - 234152 skb_re 22:07 ? 00:00:00 php-fpm: pool www 0 R root 2940 2472 0 80 0 - 25811 - 22:18 pts/0 00:00:00 grep nginx

此外,使用sudo nginx -t不会改变任何东西。同样奇怪的是,即使nginx没有运行,也存在nginx.pid。删除pid文件只会将错误消息更改回:

nginx: [emerg] open() "/usr/share/nginx/on" failed (13: Permission denied)

删除on文件也没有区别。

nginx centos php
3个回答
4
投票

确保以超级用户身份运行。

sudo nginx -t

0
投票

运行getenforce以检查SELinux模式。如果它显示Enforcing,则通过运行setenforce 0暂时将模式设置为Permissive,然后查看您的应用程序是否可用。


0
投票

我有类似的问题

nginx: [emerg] open() "/etc/nginx/conf.d/websites.conf" failed (13: Permission denied) in /etc/nginx/nginx.conf:36

问题的原因是在特定用户下通过SSH配置配置文件。这是我如何修复它(除了chmod / chown我做了什么)。

如果启用了selinux(默认情况下在Centos中),那么

ls -Z /path/to/file 

必须将“httpd_sys_content_t”显示为安全上下文。如果您遇到类似“user_home_t”的内容,则需要通过运行来更新此内容:

chcon -v --type=httpd_sys_content_t /path/to/file 

之后像往常一样重启“nginx”或“httpd”。

参考https://wiki.centos.org/HowTos/SELinux

© www.soinside.com 2019 - 2024. All rights reserved.