我使用 nginx 作为整个解决方案的单一入口点。
我的目标是在继续之前发送一些要进行身份验证的 url。
我找到了一个名为:的模块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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果我的服务器返回并出错,例如401,则显示默认页面。我想要的是能够返回从我的身份验证服务返回的 json。没有这个,这是没用的。只显示一个通用401页面有什么意义?我想返回我的代理 json 响应。
请帮忙。
auth_request 仅用于身份验证。这个小窍门应该对你有用
error_page 401 /auth;
Run Code Online (Sandbox Code Playgroud)
身份验证错误后,它将再次转到 /auth 位置,这次是普通请求。
| 归档时间: |
|
| 查看次数: |
2894 次 |
| 最近记录: |