url 匹配 "location" 标签有什么问题?

What's wrong with url matching in "location" tag?

这是我第一次在 Debian 上使用 nginx。 所以,我在 /var/www/gis/index.html 中放置了一个 html 页面 我将 nginx 配置为:

server {
        listen 80;
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name localhost;

        ssl_certificate /etc/ssl/certs/localhost.crt;
        ssl_certificate_key /etc/ssl/private/localhost.key;

        ssl_protocols TLSv1.2 TLSv1.1 TLSv1;

        location / {

        root /var/www/gis;
        index index.html;

        }

如果在浏览器中输入 https://localhost,我可以看到我的页面。 但是如果我将位置标签更改为

        location /gis {  ## or location = /gis ##)

        root /var/www/gis;
        index index.html;

        }

我希望在 https://localhost/gis/ 获取我的网站,但出现错误 404。我做错了什么?

使用此配置,nginx 期望在 /var/www/gis/gis/ 处找到您的 index.html。您可以使用

location /gis {
    root /var/www;
    index index.html;
}

location /gis {
    alias /var/www/gis;
    index index.html;
}