【问题标题】:403 nginx error - permissions denied403 nginx 错误 - 权限被拒绝
【发布时间】:2016-04-21 12:59:32
【问题描述】:

当我尝试使用 nginx 访问域时出现 403 禁止错误。我得到的 nginx 日志是:

[error] 13656#0: *4 "/var/www/example.com/www/index.php" is forbidden (13: Permission denied), client: 31.179.107.194, server: example.com, request: "GET / HTTP/1.1", host: "example.com"

/var/www/ 具有递归 777 权限。站点可用的配置是:

#HTTP serve
#
server {
        listen   80;

        root /var/www/example.com/www/;
        index index.php index.html index.htm;

        server_name example.com;

        access_log /var/log/nginx/example.com.access.log combined buffer=1024k;
        error_log /var/log/nginx/example.com.error.log;

        client_max_body_size 128M;

        if (!-e $request_filename) {
                rewrite ^/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/$ /index.php?controller=$1&action=$2 last;
        }

        location ~ \.php$ {
                if (!-f $document_root/$fastcgi_script_name){
                        return 404;
                }

                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                proxy_connect_timeout 600s;
                proxy_read_timeout 600s;
                include fastcgi_params;
        }

        location ~ /\.ht {
                deny all;
        }
}

nginx.conf 包含user root; 指令。

怎么了?

【问题讨论】:

    标签: php nginx


    【解决方案1】:

    一个可能的原因是您使用的是 SELinux。见Why does Nginx return a 403 even though all permissions are set properly?。

    另外,设置user root 存在安全风险,不推荐。建议使用像“www-data”或“nobody”这样的非特权用户,以及允许该用户访问所需的最少数据的权限。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-25
      • 2021-03-27
      • 2017-11-03
      • 2015-05-26
      相关资源
      最近更新 更多