1

Is it possible to use Nginx on my personal VPS to act as a reverse proxy in front of Heroku (running a Ruby on Rails app)?

I'd like to do this because I want to route standard requests (i.e. GET http://mydomain.com) to my Rails app, but various subdomain requests (i.e. GET http://joe.mydomain.com) to a separate server.

As a bit of a part 2 (assuming this is possible), what are the correct Nginx proxy headers to set in this case? I usually do the following when using Nginx in front of Unicorn:

proxy_redirect off;
proxy_read_timeout 5m;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header   X-Real-IP        $remote_addr;
proxy_set_header   X-Forwarded-Proto  http;

As it is in nearly every single tutorial, but I'm not knowledgable enough to know which apply (or are missing) in this case.

Help would be greatly appreciated!

Brandon
  • 191
  • 2
  • 6

1 Answers1

3

It is possible to do what you are proposing through proxy_pass (http://wiki.nginx.org/HttpProxyModule#proxy_pass) but it would be easier to route these requests through DNS.

To use the apex domain for Heroku, you can use ALIAS records at DNSimple or ANAME records at DNS Made Easy and regular A records for your subdomains.

However, my own site has the domain apex set to A record to nginx, which straight up redirects to www, which is a CNAME to heroku. More about what is supported/suggested is here: https://devcenter.heroku.com/articles/custom-domains

GregB
  • 178
  • 5
  • 1
    Agreed. The only reason for doing something like this not through DNS is if you need the flexibility to make different *paths* go to different servers (i.e., example.org/foo/ -> server A, example.org/bar -> server B). – Scrivener Feb 03 '13 at 19:13
  • Sounds like it makes sense. I'll give this a try and report back! Thanks. – Brandon Feb 03 '13 at 21:41