Nginx从错误的根读取站点文件

问题描述 投票:0回答:2

自从我在我的网站启用/默认配置中通过SSL设置HTTPS后,Nginx正在读取/usr/share/www/html而不是/var/www/html。在我的任何文件中都没有引用/usr/.../html(当我使用grep -r时)所以我不知道为什么会发生这种情况。

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name MY_WEBSITE.TLD; # Before you ask, yes
    return 302 https://$server_name$request_uri;
    root /var/www/html;
}

server {
    listen 443 ssl http2 default_server;
    listen [::]:443 ssl http2 default_server;
    include snippets/self-signed.conf;
    include snippets/ssl-params.conf;

    index index.html index.htm index.nginx-debian.html index.php;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}

显然我已经定义了根。为什么不工作?

php ssl nginx https config
2个回答
1
投票

您的配置描述了两个独立的服务器 - 而不是一台服显而易见的是,您可以将它们包含在sites-available/中的单个文件中,但从技术上讲,它们是不同的独立服务器,您可以将每个server块拆分为不同的sites-available/配置文件。

记住这一点,检查每台服务器的内容。您在端口80上有一个服务器,其中指定了root。一切都很好。

您在端口443上有另一台服务器。这是一个完全独立的服务器,而不是另一个端口上的同一服务器。它没有指定root,因此nginx将回退到某个默认的根位置,由编译时开关或特定于发行版的变量as described in this SO question确定。


0
投票

Aaaaand这一切都回到我指定php7.0-fpm的错误目录。因为它当然有!感谢@ Do not Panic和@Keven_Kinsey帮助我。它最终加载正确。

© www.soinside.com 2019 - 2024. All rights reserved.