Welcome! Log In Create A New Profile

Advanced

How to redirect to login page after auth_request returns 401

Posted by jjakub 
How to redirect to login page after auth_request returns 401
July 30, 2020 08:47AM
I do auth_request /auth;
as described in https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-subrequest-authentication/

How can I redirect to login page if /auth returns 401 or 403?

I tried with

error_page 401 403 = @error401;

location = ^/securedUrl {
add_header dbg-header dbg_ws_3;
auth_request /auth;
proxy_pass http://auth-module:8080;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass_header x-remaining-session-time;
}

location @error401 {
return 302 /login-module/login;
}

location = /auth {
internal;
rewrite ^/(.*) /is-authorized break;
proxy_pass http://auth-module:8080;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
}
but it doesn't work, I get 401 in browser



Edited 1 time(s). Last edit at 07/30/2020 08:52AM by jjakub.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 202
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready