当我尝试使用 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;
指令。
怎么了?
一个可能的原因是您正在使用 SELinux。请参阅为什么 Nginx 在正确设置所有权限的情况下仍返回 403?。
此外,设置user root
存在安全风险,不建议这样做。建议使用非特权用户(如"www-data"或"nobody"),以及允许该用户访问所需最少数据的权限。