# Path-based reverse proxy

**URL:** <https://www.ruby-forum.com/t/path-based-reverse-proxy/194487>\
**Category:** NGINX\
**Created:** [September 6, 2010, 4:39pm UTC](https://www.ruby-forum.com/t/path-based-reverse-proxy/194487 "2010-09-06T16:39:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cantabile](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e5b9ba/32.png) [@cantabile](https://www.ruby-forum.com/u/cantabile)\
**Post date:** [September 6, 2010, 4:39pm UTC](https://www.ruby-forum.com/t/path-based-reverse-proxy/194487/1 "2010-09-06T16:39:43Z")

</div>

Hi all,

I’m new to nginx and I’m looking for a path-based reverse-proxy.  
Here’s my setup.

nginx server has $PUB\_IP, listening to port 80  
I have two webservers with $IP1 and $IP2

I want to access my main server from a browser with http://$PUB\_IP and  
the second server with http://$PUB\_IP/myapp

I can’t find how to do it.

I tried defining two servers in sites-available, default and myapp, but  
since they listen on the same port, I always have the same server with  
both http://$pub\_ip and http://$pub\_ip/myapp. Seems logical to me since  
nothing can tell nginx wich server it was supposed to redirect to.

I have tried to put another location in site-available/default, like  
this

server {  
…  
location / {  
proxy\_pass http://$IP1  
}

location /myapp {  
proxy\_pass http://$IP2  
}  
}

But that doesn’t work. I can only have the main page of site2, not even  
the images in the same directoriy. And by the way that looks wrong,  
'cause site2 isn’t another directory of site1, it’s another  
webserver…

So could somebody give me an example or a little help with that ?

Thx a lot !

PS : I have no access to the dns. I can’t play with the names like  
[www.site1.com](http://www.site1.com) and [www.site2.com](http://www.site2.com)

Posted at Nginx Forum:

> **[path-based reverse proxy](https://forum.nginx.org/read.php?2,127024,127024#msg-127024)**
>
> Hi all, I'm new to nginx and I'm looking for a path-based reverse-proxy. Here's my setup. nginx server has $PUB\_IP, listening to port 80 I have two webservers with $IP1 and $IP2 I want to access my main server from a browser with http://$PUB

---

<div class="post-metadata">

**Author:** ![cantabile](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e5b9ba/32.png) [@cantabile](https://www.ruby-forum.com/u/cantabile)\
**Post date:** [September 6, 2010, 4:39pm UTC](https://www.ruby-forum.com/t/path-based-reverse-proxy/194487/2 "2010-09-06T16:39:54Z")

</div>

On Sat, Sep 04, 2010 at 05:25:25AM -0400, cantabile wrote:

> Hi all,
> 
> I’m new to nginx and I’m looking for a path-based reverse-proxy.  
> Here’s my setup.
> 
> nginx server has $PUB\_IP, listening to port 80  
> I have two webservers with $IP1 and $IP2
> 
> I want to access my main server from a browser with http://$PUB\_IP and  
> the second server with http://$PUB\_IP/myapp
> 
> I can’t find how to do it.
> 
> I tried defining two servers in sites-available, default and myapp, but  
> since they listen on the same port, I always have the same server with  
> both http://$pub\_ip and http://$pub\_ip/myapp. Seems logical to me since  
> nothing can tell nginx wich server it was supposed to redirect to.
> 
> I have tried to put another location in site-available/default, like  
> this
> 
> server {  
> …  
> location / {  
> proxy\_pass http://$IP1  
> }
> 
> location /myapp {  
> proxy\_pass http://$IP2  
> }  
> }
> 
> But that doesn’t work. I can only have the main page of site2, not even  
> the images in the same directoriy. And by the way that looks wrong,  
> 'cause site2 isn’t another directory of site1, it’s another  
> webserver…

The problem that images in $IP2’s HTML has links something like  
 ![](https://www.ruby-forum.com/...) while you need ![](https://www.ruby-forum.com/myapp/...).

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![cantabile](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e5b9ba/32.png) [@cantabile](https://www.ruby-forum.com/u/cantabile)\
**Post date:** [September 7, 2010, 9:44am UTC](https://www.ruby-forum.com/t/path-based-reverse-proxy/194487/3 "2010-09-07T09:44:25Z")

</div>

On Sun, Sep 05, 2010 at 12:28:44PM -0700, UnclePhil wrote:

> Try with the location in reverse orde ;  
> More specific first, root at last position
> 
> I had a similar problem and this was solving it

If you use locations without regexes, the order has no meaning.

> > I have tried to put another location in site-available/default, like  
> > š š š š š š}  
> > Thx a lot !
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![cantabile](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e5b9ba/32.png) [@cantabile](https://www.ruby-forum.com/u/cantabile)\
**Post date:** [September 8, 2010, 12:24pm UTC](https://www.ruby-forum.com/t/path-based-reverse-proxy/194487/4 "2010-09-08T12:24:26Z")

</div>

Thank you very much for your answers !  
Sorry for the delay, I was off a few days.

Cantabile

Posted at Nginx Forum:

> **[Re: path-based reverse proxy](https://forum.nginx.org/read.php?2,127024,128337#msg-128337)**
>
> Hi all, I'm new to nginx and I'm looking for a path-based reverse-proxy. Here's my setup. nginx server has $PUB\_IP, listening to port 80 I have two webservers with $IP1 and $IP2 I want to access my main server from a browser with http://$PUB
