Welcome! Log In Create A New Profile

Advanced

Remove path prefix during proxy_pass

Vignesh VR
February 12, 2016 12:36PM
Hi,

I am trying to use Nginx as a reverse proxy and want to redirect to
different upstream servers based on the URL. Looking to use the path prefix
to distinguish the upstream servers to be used. But the issue is the path
prefix gets sent to the upstream server which I don't want to.

For eg., this is what I am trying to do:

Nginx Server: nginx (External IP)

upstream 1: upstream1 (Internal IP)

upstream 2: upstream2 (Internal IP)

Desired outcome:
http://nginx/server1 --------------> http://upstream1

http://nginx/server2 ----------------> http://upstream2


The problem I am having is that http://nginx/server1 gets translated to
http://upstream1/server1. I am not able to remove the path prefix when the
traffic gets directed to the upstream servers.

I have tried most of the suggestions on the net:


location /server1/ {
proxy_pass http://upstream1/;
}

(tried without slash)
location /server1/ {
proxy_pass http://upstream1;
}


(tried using regex)
location /server1/ {
rewrite ^/server1/(.*) /$1 break;
proxy_pass http://upstream1/;
}


All of the above results in varied behaviors but none gives the desired
outcome. I am currently using a non-commercial version of nginx.

And please note that I am using IP addresses everywhere and not hostnames.
So name resolution issues anywhere here.

Any guidance / help / pointers will be highly appreciated.

Thanks
Vigs.
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Remove path prefix during proxy_pass

Vignesh VR February 12, 2016 12:36PM

Re: Remove path prefix during proxy_pass

Maxim Dounin February 12, 2016 08:48PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 70
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready