Nginx配置问题:获得403 Forbidden

时间:2016-01-24 22:42:36

标签: php nginx config

我正在尝试使用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错误。

1 个答案:

答案 0 :(得分:1)

您在;指令上缺少server_name,这通常是语法错误,但在您的情况下,它会转换为:

server_name localhost index index.php index.html index.htm;

这可能是一个奇怪的服务器名称列表,但更重要的是,这意味着您没有index指令。这意味着每当您尝试列出/等目录时,您将获得HTTP 403响应代码。

相关问题