server {
server_name 127.0.0.1;
listen 3000;
location = /auth {
internal;
proxy_pass http://127.0.0.1:8088/auth;
}
location / {
auth_request /auth;
# force Nginx to preserver the response proxy_set_header
auth_request_set $falure_reason $sent_http_x_authenticationfail;
error_page 401 =200 /login;
proxy_pass http://127.0.0.1:9000;
}
location /login {
proxy_pass http://127.0.0.1:8081/sso;
}
}
I am working on a authentication service. The idea is when a request hit root, it will be authenticated(checking token) through /auth and the auth server sits http://127.0.0.1:8088/auth to handle all auth request. Then if the token is not set, auth server will respond a 401 and error page will catch that and route to /login to proxy to my login server http://127.0.0.1:8081/sso. But the problem is, when I go through / -> /auth -> /login, the request url return from server is still 127.0.0.1:3000/sso instead of ttp://127.0.0.1:8081/sso because afterward I need to send a subsequent post request to http://127.0.0.1:8081/sso with user login id/password. But the nginx point me to 127.0.0.1:3000/sso on the browser.