【问题标题】:403 Forbidden on local nginx when the root directory is changed403 Forbidden on local nginx 当根目录改变时
【发布时间】:2016-05-20 11:13:35
【问题描述】:

我在笔记本电脑(运行 Arch Linux)上设置了 nginx、php、mysql 和 phpMyAdmin。一切都很好,直到我尝试在我的主目录中移动根目录。

这是我正在使用的 nginx 配置文件:

server {
    ############### General Settings ###################
    listen       80;
    server_name  localhost;
    root   /home/me/Development;
    charset utf-8;

    ############## Document Root #####################
    location  / {
        index  index.php index.html index.htm;
        autoindex on;
    }

    ############## PHPMyAdmin #######################
    #location /phpmyadmin {
    #   rewrite ^/* /phpMyAdmin last;
    #}

    ############# Error redirection pages ################
    error_page  404               NGINX/html/404.html;
    error_page  500 502 503 504   NGINX/html/50x.html;

    ############## Proxy Settings for FastCGI PHP Server #####
    location ~ \.php$ {
         if ($request_uri ~* /phpmyadmin) {
            root /usr/share/nginx/html;
        }

        try_files  $uri =404;
        #fastcgi_pass 127.0.0.1:9000; (depending on your php-fpm socket configuration)
        fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi.conf;
    }

    location ~ /\.ht {
        deny  all;
    }

}

所以我正在尝试制作这个“开发”文件夹——我将存储我的所有 php 项目的文件夹。而且我想将 phpMyAdmin 保留在其默认位置。 现在,如果我尝试访问 phpMyAdmin 或新位置上的任何 php 文件,我会得到 403 Forbidden - 错误消息:

2016/05/20 14:11:46 [crit] 5292#5292: *3 stat() "/home/me/Development/test.php" failed (13: Permission denied), client: 127.0.0.1, server: localhost, request: "GET /test.php HTTP/1.1", host: "localhost"

它应该对 linux 组和权限做一些事情,但无法弄清楚。

【问题讨论】:

    标签: nginx


    【解决方案1】:

    这是 selinux,谷歌禁用它或配置它以允许你需要做的事情。 当您的权限设置正确并且日志显示“权限被拒绝”时,它就是 selinux。

    【讨论】:

      【解决方案2】:

      您正在使用 HTTP 来获取您的页面。现在 HTTP 向您返回错误代码“403”,根据 RFC 2616 表示“服务器理解请求,但拒绝执行它。授权无济于事,请求不应重复。”

      出现此错误代码的两个可能原因

      Authentication was provided, but the authenticated user is not permitted to perform the requested operation.
      The operation is forbidden to all users. For example, requests for a directory listing return code 403 when directory listing has been disabled.
      

      尝试检查您的文件权限。有解决办法。

      【讨论】:

      • 是的,我也是这么想的,但是给它一个 777 权限并没有帮助。会不会是我的nginx配置不对?
      • 我对nginx一无所知。但我可以看到其他人也提出了非常非常相似的问题。这意味着这是 nginx 非常常见的问题,或者某些特定版本存在此问题。最好查看 nginx 开发者论坛或发送邮件给他们。也许他们会回复。
      • 是的,我也发现了很多这样的问题没有答案。到目前为止,它与nginx配置有关。感谢您的宝贵时间。
      【解决方案3】:

      我遇到了类似的问题:我也得到了 403 错误代码,并尝试使用 chmod 777 配置文件的权限。仍然是相同的结果。 我的问题是我用sudo nginx 启动了 nginx 网络服务器,而不是用我的用户和我的权限启动它。只需使用nginx 而不使用sudo 启动服务器,就可以了。 我希望这对某人有所帮助。

      【讨论】:

        【解决方案4】:

        如果用户是 sudo,则使用 ls -l 命令检查文件夹的所有者和模式,然后运行此 sudo chown -R yourusername:yourusername Development 并同时运行 sudo chmod -R 777 Development

        【讨论】:

        • 谢谢,我试过了,没有结果。仍然得到 403。
        • 我这边的大 -1,不要使用 777 这将允许所有用户读取/写入和访问此文件夹,它还会向您不知道如何设置的任何其他人发送危险信号权限安全。
        猜你喜欢
        • 2016-01-31
        • 2020-06-04
        • 2013-11-02
        • 1970-01-01
        • 1970-01-01
        • 2018-05-06
        • 2021-06-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多