Welcome! Log In Create A New Profile

Advanced

proxy_redirect based on path

Posted by marcuskrantz 
proxy_redirect based on path
May 22, 2013 09:41AM
Hi,

I have a Nginx as a reverse proxy for my Java application. The Nginx is configured with SSL to communicate with the outside and talk plain http with my Java application. This means that the redirects needs to be rewritten by Nginx in order to prevent the Location header to start with http://.

However, there is one redirect (that redirects users to an identity provider on Internet) where I do not wish to rewrite the Location header at all. And in some way, I can't make this work. The idp is an idp to use in dev-mode and thus the call is not encrypted.

I need some guidance in how to configure Nginx to support the scenario described above. My current configuration looks like:

server {
...
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_redirect http:// https://;
}
}

The url http://127.0.0.1:8080/oauth/authorize responds with a 302 Location https://external-idp.com but I want it to be http://external-idp.com. In my Java application the logs clearly says that "Redirecting to http://external-idp.com" so Nginx rewrites this header to https:// which is expected due to my configuration but what changes is needed to make the proxy_redirect not applicable on all paths?

/Marcus
Re: proxy_redirect based on path
May 22, 2013 10:11AM
Hello, try adding another location block, i.e. location /oauth { proxy_pass.....
Re: proxy_redirect based on path
May 22, 2013 11:26AM
That solved my issue! I was actually doing that at first, but the configuration didn't bite with nginx reload. Thanks a lot!
Sorry, only registered users may post in this forum.

Click here to login

Online Users

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