Nginx 配置问题:获取 403 Forbidden

Nginx config issue: getting 403 Forbidden

我正在尝试使用 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 响应代码