Nginx Basic Auth not working before re-directing to a subpath of the website

Majid M A majid210484 at gmail.com
Fri Feb 19 11:47:28 UTC 2021


Dear Nginx Users,

I have a scenario that whenever a user hits the website (
https://abc.test.com), it should re-direct to the sub-path (/xxx/yyy/) of
the website (ex: https://abc.test.com/xxx/yyy).

So re-direction to a website's sub-path (https://abc.test.com/xxx/yyy) is
working.

I have implemented http basic auth, so whenever the user is re-directed to
sub-path /xxx/yyy/, the basic auth should come into effect and then the
website has to be re-directed.

The issue is basic auth is not coming into effect before re-directing to
the web-site's sub-path it just re-directs.

This is how my nginx config looks like

    listen 443 ssl;
    server_name aa.bb.com;
    set $backend "https://abc.test.com:8080/";

     location / {
       proxy_pass $backend;
       proxy_pass_header  Authorization;
       auth_basic "Access Denied or Restricted";
       auth_basic_user_file /etc/nginx/.htpasswd;
       return 301 https://abc.test.com:8080/xxx/yyy/;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header Host aa.bb.com;
       client_max_body_size       10m;
       proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "upgrade";
       proxy_read_timeout 900;
    }
}
If you see above in the location block i am using basic auth just
before the re-direction, but the basic auth is not in effect.

Any ideas or suggestions are highly appreciated.

nginx version: nginx/1.16.1

Thanks & Regards,
Majid M A
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20210219/7cbbecd6/attachment.htm>


More information about the nginx mailing list