我正在尝试使用Nginx设置Web应用程序,但是在尝试访问它时,我收到403错误。我遵循了各种不同的方法来解决此问题,包括确保设置了我的权限但无济于事。
这是 Web 应用程序的配置:
server {
listen 80;
server_name localhost
index index.php index.html index.htm;
root /usr/share/nginx/html/my-app/webapp;
port_in_redirect off;
# Use cached or actual file if they exists, otherwise pass request to WordPress
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
# Deny access to hidden files
location ~* /'.ht {
deny all;
access_log off;
log_not_found off;
}
# Pass PHP scripts on to PHP-FPM
location ~* '.php$ {
try_files $uri /index.php;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
我跑chmod -R 777 my-app
给它所有权限。
但我仍然收到 403 错误。
您在server_name
指令上缺少;
,这通常是语法错误,但在您的情况下,它转换为:
server_name localhost index index.php index.html index.htm;
这可能是一个奇怪的服务器名称列表,但更重要的是,这意味着您没有index
指令。这意味着,每当您尝试列出目录(如 /
)时,您都会收到 HTTP 403 响应代码。