Help With Locations and Proxying

Bryan Richardson btricha at gmail.com
Mon Jun 21 22:32:16 MSD 2010


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, 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, and I want to access my second Ruby app by
navigating to 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 directly or by navigating to
bryan.example.com. However, I can only access my second Ruby app at
port 3011 by navigating to bryan.example.com:3011 - navigating to
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 to become the root URL for my Ruby
application, such that navigating to 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;

  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



More information about the nginx mailing list