我有一个可以进行授权的服务/auth-admin
。我可以确认它适用于静态网页。但是,如果页面有一些 api 调用(如 phpmyadmin 中的登录),auth_request
则会破坏它。设置 的正确方法是什么 auth_request
?
server {
listen 443 ssl;
server_name example.com;
location / {
proxy_pass http://192.168.1.13:8085;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /auth-admin {
internal;
proxy_pass http://192.168.1.13:8085/auth.php?admin;
}
location /phpmyadmin/ {
auth_request /auth-admin;
proxy_pass http://192.168.1.13:8086/;
add_header X-Frame-Options "SAMEORIGIN";
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
答案1
经过大量的挖掘之后,您需要遵循以下步骤来处理 POST 请求。
location /auth-admin {
internal;
proxy_pass http://192.168.1.13:8085/auth.php?admin;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
}