Loo*_*ing 5 nginx proxy authentication redirection
我正在尝试使用 OAuth2 服务器(授权代码流)对 NGINX 请求进行身份验证,该服务器会将客户端重定向到登录页面。是否可以使用 auth_request 指令来实现这一点?这是我的 nginx.conf:
server {
listen ${NGINX_PORT};
proxy_send_timeout 600;
proxy_connect_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
client_max_body_size 100m;
absolute_redirect off;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log warn;
location / {
auth_request /authn;
gzip_static on;
index index.html;
root /usr/share/nginx/html;
try_files $uri $uri/ @index;
}
location @index {
root /usr/share/nginx/html;
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
expires 0;
try_files /index.html =404;
}
location /api {
set $target http://gateway:8030/api;
proxy_pass http://gateway:8030/api;
}
location /authn {
set $target http://gateway:8030/authn;
proxy_pass http://gateway:8030/authn;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
proxy_pass_request_headers on;
proxy_intercept_errors on;
recursive_error_pages on;
error_page 301 302 303 307 308 @handle_redirect;
}
location @handle_redirect {
set $redirect_url $upstream_http_location;
proxy_pass $redirect_url;
}
}
Run Code Online (Sandbox Code Playgroud)
但我的 oauth 网关返回没有 schema://host:port 的重定向,我得到
invalid URL prefix in "/oauth2/authorization/gateway" while sending to client
Run Code Online (Sandbox Code Playgroud)
为什么 NGINX 不明白它必须在重定向中保留主机和端口信息,我该如何解决这个问题?
| 归档时间: |
|
| 查看次数: |
1763 次 |
| 最近记录: |