nginx http auth请求模块仅返回默认错误页面

我使用Nginx作为我整个解决方案的单一入口点.

我的目标是在继续之前发送一些网址进行身份验证.

我找到了一个名为:ngx_http_auth_request_module的模块,它适合于解决我的问题.

http://nginx.org/en/docs/http/ngx_http_auth_request_module.html

我正在编译我的Nginx:./ configure –with-http_auth_request_module

我的代码看起来像这样:

http {

    server {
        listen       8080 default_server;

        server_name _;

        location /api {
            auth_request /auth;
            proxy_pass  http://localhost:8000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        }

        location = /auth {
            proxy_pass http://localhost:8000/auth/user;
            proxy_pass_request_body off;
            proxy_set_header Content-Length "";
            proxy_set_header X-Original-URI $request_uri;
        }

    }
}

我的问题是,如果我的服务器返回错误,如401,则显示页面.我想要的是能够返回从我的身份验证服务返回的json.没有这个就没用了.只显示一个通用的401页面有什么意义?我想返回我的代理json响应.

请帮忙.

解决方法:

auth_request仅用于身份验证.这个小黑客应该适合你

error_page 401 /auth;

在auth错误之后它将再次进入/ auth位置,这次是普通请求.

相关文章

Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一...
本地项目配置 1 复制 luffy/settings/dev.py为prop.py 修改l...
nginx不仅可以隐藏版本信息,还支持自定义web服务器信息 先看...
一 、此次漏洞分析 1 nginx HTTP/2漏洞 [nginx-announce] ng...
###进入nginx 目录cd /usr/local/nginx###递归显示 2 级目录...
在cmd命令窗口输入下面命令进行查看 tasklist /fi "ima...