微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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位置,这次是普通请求.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐