首页 > 解决方案 > NGINX 位置给出 404 错误,即使目录存在

问题描述

我的 NGINX 配置文件是这样设置的

root /var/www/html/tests_manager/webroot;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html;
    server_name qa.kloc.co.uk; # managed by Certbot

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            rewrite ^/uploads/(.*) /uploads/uploadsController.php last;
            try_files $uri $uri/ =404;
    }

    location /support {
        root /var/www/html/support-manager/webroot; #I have checked, this directory exists.
    }

    location = /notifications {
        proxy_pass http://localhost:8080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
    }

    location = /supportSocket {
        proxy_pass http://localhost:8081;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
            include snippets/fastcgi-php.conf;

            # With php7.0-cgi alone:
            #fastcgi_pass 127.0.0.1:9000;
            # With php7.0-fpm:
            fastcgi_pass unix:/run/php/php7.3-fpm.sock;
    }

我希望该/support位置重定向到不同的根目录,以便当用户尝试访问时,qa.kloc.co.uk/support他们会在目录中看到该站点/var/www/html/support-manager/webroot

我的问题是,每当我尝试浏览此 URL 时,都会收到 404 错误。我检查了访问日志,但它们没有帮助。我只是看到

GET /support/index.php HTTP/1.1" 404 209

错误日志中没有任何内容。

我尝试使用重写(例如使用 /uploads/),但我认为我无法逃脱根目录。我也尝试使用location = /supportlocation ^~ /support但这些都没有效果。

我也尝试将/var/www/html/support-manager/webroot/目录的所有者更改为,www-data但这并没有什么不同。

请帮助我以正确的方式编写/支持位置

标签: nginx

解决方案


推荐阅读