# Help With Locations and Proxying

**URL:** <https://www.ruby-forum.com/t/help-with-locations-and-proxying/190506>\
**Category:** NGINX\
**Created:** [June 21, 2010, 8:39pm UTC](https://www.ruby-forum.com/t/help-with-locations-and-proxying/190506 "2010-06-21T20:39:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![roxah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/54ee81/32.png) [@roxah](https://www.ruby-forum.com/u/roxah)\
**Post date:** [June 21, 2010, 8:39pm UTC](https://www.ruby-forum.com/t/help-with-locations-and-proxying/190506/1 "2010-06-21T20:39:21Z")

</div>

Hello All,

I love using Nginx in front of Ruby web applications powered by  
Thin… it’s just so reliable. So, I’m hoping someone can help me with  
my problem. I’m sure it’s just a proxy configuration issue, but I  
don’t know enough about all the options and terminology to understand  
how to fix it.

Here’s my scenario:

I own a subdomain at my company, and I’m not able to get a second one.

I currently have one Ruby web application running behind Nginx right  
now, and all is working fine. I simply do a proxy\_pass inside a  
“location /” directive.

I’m wanting to add a second Ruby application at “location /planner/”,  
but when I configure my Nginx config file to do a proxy\_pass to a  
separate Ruby web app process inside that directive I get a “Not  
Found” error when I try to navigate to the page. I can get to the Ruby  
app just fine if I navigate to the right port, but not if I try to  
navigate to the location specified for my subdomain as configured in  
Nginx.

For example, assume my subdomain is [bryan.example.com](http://bryan.example.com), my first Ruby  
app is listening on port 3001, my second (new) Ruby app is listening  
on port 3011, I want to access my first Ruby app by simply navigating  
to [bryan.example.com](http://bryan.example.com), and I want to access my second Ruby app by  
navigating to [bryan.example.com/planner](http://bryan.example.com/planner). The first situation works  
fine - I can access by first Ruby app at port 3001 by either  
navigating to [bryan.example.com:3001](http://bryan.example.com:3001) directly or by navigating to  
[bryan.example.com](http://bryan.example.com). However, I can only access my second Ruby app at  
port 3011 by navigating to [bryan.example.com:3011](http://bryan.example.com:3011) - navigating to  
[bryan.example.com/planner](http://bryan.example.com/planner) tells me “Not Found”.

> From looking at the debug errors from Nginx, it looks like Nginx is  
> trying to pass the /planner portion of the URL to the Ruby  
> application, which I don’t want because I don’t have a route in my web  
> application that matches /planner. Essentially, I’d like  
> [bryan.example.com/planner](http://bryan.example.com/planner) to become the root URL for my Ruby  
> application, such that navigating to [bryan.example.com/planner/admin](http://bryan.example.com/planner/admin)  
> would just pass the /admin portion of the URL to the Ruby application,  
> but I’m not sure how to do that. I’m assuming it has something to do  
> with some of the other proxy options available…

Here’s some excerpts from my Nginx config file:

upstream inventory {  
server 192.168.101.1:3001;  
}

upstream planner {  
server 192.168.101.1:3011;  
}

server {  
listen 80;  
server\_name [bryan.example.com](http://bryan.example.com);

access\_log /var/log/nginx/bryan-access.log;  
error\_log /var/log/nginx/bryan-error.log debug;

location / {  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
proxy\_set\_header Host $http\_host;  
proxy\_redirect off;

```
proxy_pass http://inventory;

```

}

location /planner/ {  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
proxy\_set\_header Host $http\_host;  
proxy\_redirect off;

```
proxy_pass http://planner;

```

}  
}

Please help!

–  
Bryan

---

<div class="post-metadata">

**Author:** ![roxah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/54ee81/32.png) [@roxah](https://www.ruby-forum.com/u/roxah)\
**Post date:** [June 21, 2010, 9:12pm UTC](https://www.ruby-forum.com/t/help-with-locations-and-proxying/190506/2 "2010-06-21T21:12:08Z")

</div>

Hello!

On Mon, Jun 21, 2010 at 12:32:16PM -0600, Bryan R. wrote:

[…]

> From looking at the debug errors from Nginx, it looks like Nginx is  
> trying to pass the /planner portion of the URL to the Ruby  
> application, which I don’t want because I don’t have a route in my web  
> application that matches /planner. Essentially, I’d like  
> [bryan.example.com/planner](http://bryan.example.com/planner) to become the root URL for my Ruby  
> application, such that navigating to [bryan.example.com/planner/admin](http://bryan.example.com/planner/admin)  
> would just pass the /admin portion of the URL to the Ruby application,  
> but I’m not sure how to do that. I’m assuming it has something to do  
> with some of the other proxy options available…

You instructed nginx to pass url as is and it does so. If you want  
“/planner” portion to be stripped/replaced by something you have  
to use proxy\_pass with uri component, i.e. …

> location /planner/ {  
> proxy\_set\_header X-Real-IP $remote\_addr;  
> proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
> proxy\_set\_header Host $http\_host;  
> proxy\_redirect off;
> 
> ```
> proxy_pass http://planner;
> 
> ```

- 

```
proxy_pass http://planner;

```

- 

```
proxy_pass http://planner/;

```

Note trailing “/”.

Maxim D.
