使用 nginx 和 auth_request 提供一个静态文件

Serving one static file with nginx and auth_request

我正在尝试为某个位置提供静态文件服务器。它返回 404,我不知道为什么。 这是我的配置(删减了一点)

        root /home/git/website/prod/;

        location = /login {
                index login.html;
        }

        location / {
                auth_request /auth;
                try_files $uri $uri/index.html;
        }

        location = /auth {
                internal;
                proxy_pass http://127.0.0.1:5000/api/auth/logged_in;
                proxy_pass_request_body off;
                proxy_set_header Content-Length "";
                proxy_set_header X-Original-URI $request_uri;
        }


        location /api {
                proxy_pass http://127.0.0.1:5000;
        }

当我尝试访问/登录时returns 404. 为什么?

假设您的 login.html 在 root 文件夹 (/home/git/website/prod/) 中,您可能会使用:

location = /login {
    try_files /login.html =404;
}

或将=404替换为/index.html。那部分基本上是告诉 nginx 如果在服务器上找不到 /login.html 应该尝试什么。