Nginx配置问题:出现403 Forbidden错误

3

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

你正在尝试访问哪个URL? - BrokenBinary
127.0.0.1,试图在本地主机上访问它。 - ThriceGood
1个回答

1
您的 server_name 指令缺少一个 ;,这通常会导致语法错误,但在您的情况下,它被翻译为:
server_name localhost index index.php index.html index.htm;

这可能是一份奇怪的服务器名称列表,但更重要的是,它意味着您没有index指令。这意味着每当您尝试列出目录(例如/)时,您将收到HTTP 403响应代码。


是的,这似乎解决了403错误,但现在我遇到了404错误!也许我需要提一个新的问题。 - ThriceGood

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接