【问题标题】:CentOS 6.6 with Nginx 1.6.2 - Suddenly can't restart nginx - nginx: [emerg] open() “/usr/share/nginx/on” failed (13: Permission denied)CentOS 6.6 with Nginx 1.6.2 - 突然无法重启 nginx - nginx: [emerg] open() “/usr/share/nginx/on” failed (13: Permission denied)
【发布时间】:2015-05-25 06:41:10
【问题描述】:

这是一个新的安装,其中 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


    【解决方案1】:

    我有类似的问题

    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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

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

        sudo nginx -t
        

        【讨论】:

        • 实际上 nginx 在用户 www-data 上工作,将文件夹的所有者更改为它可能是个好主意。
        • 我查了一下,nginx用户是nginx
        猜你喜欢
        • 1970-01-01
        • 2019-06-18
        • 2013-08-31
        • 2019-12-17
        • 2021-01-31
        • 2022-01-02
        • 2021-11-08
        • 2016-06-06
        • 2016-03-26
        相关资源
        最近更新 更多