Francis Daly
February 19, 2021 11:06AM
On Fri, Feb 19, 2021 at 05:17:28PM +0530, Majid M A wrote:

Hi there,

> 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).

Your config shows both "proxy_pass" and "return". That is probably not
going to do what you want.

I suspect that if you just remove the "return" line, things may work
better for you.

But I am not certain what response you want to get, for each request,
so there may be some other things to check first.

Maybe you should add

location = / { return 301 /xxx/yyy/; }

as well?

> 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.

In general, the order of directives as written in nginx conf is not
important.

"return" happens before "auth_basic".

But you possibly don't need the "return" here anyway.

Good luck with it,

f
--
Francis Daly francis@daoine.org
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

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

majid210484@gmail.com February 19, 2021 06:50AM

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

Francis Daly February 19, 2021 11:06AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 182
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