Nginx – Configuring nginx as reverse proxy

nginxphusion-passenger

I am using Passenger with nginx to serve my rails app on a virtual Slice host. I am considering putting a reverse proxy for serving static content as well as handling etagged actions.

  1. Can I use my existing nginx installation and just change it to a
    reverse proxy? Do I even need a web server? What would a typical
    architecture look like in this case?

    nginx rev-proxy -> nginx web server -> passenger?
    

    or

    nginx rev-proxy ->  passenger?
    
  2. Is nginx the best choice in this case?

  3. Can my reverse proxy reside on the same Slice?

Thanks

Best Answer

  1. Yes you can use your nginx install. You don't need to proxy at all, just continue using passenger with nginx and have nginx server static content direct

  2. Popular opinion is probably, if you had Apache or Squid running you might consider using them, but since you have nginx already, nginx is a great choice. Avoiding using passenger to serve static files may offer significant performance gains - but of course you milage will vary.

  3. Same server/slice probably fine, if your traffic was so large that it had an impact, sure move it to another server, but there is no reason to proxy it, just change the urls accordingly - this is what serverfault does.

An example config file would be:

server {
listen www.example.com:80;

server_name  www.example.com;

    location ~* ^.+\.(jpg|jpeg|gif|png|css|bmp|js|ico|swf)$ {
       root  /home/static/files;
       expires 7d;
    }

    location / {
       root /home/rails_app;
       passenger_enabled on;
    }     

}

Obviously add any additional files types as necessary.