nginx auth_request始终为真,从未见过

时间:2018-09-25 14:19:06

标签: nginx

我通过uwsgi通过auth_request指令将Nginx与Flask结合使用,如下所示:

    location /protected/ {
            auth_request /auth;
            auth_request_set $auth_status $upstream_status;
            proxy_pass http://127.0.0.1:8080/protected/;
    }

    location = /auth/ {
            #internal;
            try_files $uri @uwsgi_socket;
    }

    location / {
            try_files $uri @uwsgi_socket;
    }

没有auth_request参数,访问/ protected即可。

当访问路径/ auth或/ anyfile时,我得到了预期的答案。但是,当我尝试访问/ protected时,出现以下nginx错误:

sept. 25 15:12:01  nginx[12548]:  nginx: 2018/09/25 15:12:01 [error] 12548#12548: *3 auth request unexpected status: 301, client: 172.18.8.143, server: _, request: "GET /protected/ HTTP/1.1", host: "myhost.com"

似乎/ auth从未请求访问/ protected,因为uwsgi不会显示任何日志,但是:

[pid: 12155|app: 0|req: 55/55] 192.18.8.146 () {56 vars in 1256 bytes} [Tue Sep 25 15:27:06 2018] GET /protected/ => generated 297 bytes in 2 msecs (HTTP/1.1 301) 3 headers in 152 bytes (1 switches on core 0)

由于/ protected应该重定向到:8080,因此不应该发生

1 个答案:

答案 0 :(得分:0)

问题归因于“ /”:

    location = /auth {
            try_files $uri @uwsgi
    }

工作完美