NginX-won';在go web应用程序之前,不要提供静态文件index.html

NginX-won';在go web应用程序之前,不要提供静态文件index.html,nginx,nginx-reverse-proxy,Nginx,Nginx Reverse Proxy,我正在使用nginx为运行在ubuntu18.04服务器上的go web应用提供服务。我想让它在我进入mydomain.com时首先响应index指令,但在我下面的nginx配置中,它直接进入web应用程序并忽略我的index.html文件。如果我获得mydomain.com/index.html,它确实可以工作,但不会从索引中获得该文件/var/log/nginx/error.log没有错误 使用chmod 640将静态文件下载到root:www-data 我的静态文件位于/srv/stati

我正在使用
nginx
为运行在
ubuntu18.04
服务器上的go web应用提供服务。我想让它在我进入
mydomain.com
时首先响应index指令,但在我下面的
nginx
配置中,它直接进入web应用程序并忽略我的index.html文件。如果我获得
mydomain.com/index.html
,它确实可以工作,但不会从索引中获得该文件<代码>/var/log/nginx/error.log没有错误

使用
chmod 640
将静态文件下载到
root:www-data

我的静态文件位于
/srv/static/
,我的go web服务器位于
/srv/web/

以下是我的站点可用配置文件:

server {
       listen         80;
       server_name    mydomain.com;
       return         301 https://$server_name$request_uri;
}

server {
        server_name mydomain.com;

        listen 443 ssl;

        ssl on;
        ssl_certificate     /etc/letsencrypt/live/mydomain.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem;

        root /srv/static; 

        index index.html;

        location / {          
           try_files $uri @proxy;
        }

        location @proxy {
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header X-Forwarded-For $remote_addr;
           proxy_set_header Host $host;
           proxy_pass http://127.0.0.1:8000;
        }
}

我试过了,但它返回的目录列表不是我想要的。也许我应该再试一次。你确定你也有索引指令吗<代码>index.html目录列表仅在找不到索引时显示。如果仍然不起作用,请尝试添加
index index.html
位置/
块它现在可以工作了,谢谢!我以前一定在没有index指令的情况下尝试过。这个问题更适合ServerFault。
location / {
    try_files $uri $uri/ @proxy; # add $uri/ here
}