Search code examples
ruby-on-railsamazon-web-servicesnginxamazon-ec2passenger

Rails deployment, bundle exec rails s vs Nginx and Passenger


I recently deployed a rails app to a ec2 instance on AWS. This was my first time doing deployment like this.

I was reading around and most sources seem to suggest rails deployment with Nginx and Passenger.

Right now I run bundle exec rails s -p 80 -b 0.0.0.0 and my app runs great when I go to my ec2 url.

I was wondering what are the upsides and downside of just running bundle exec rails s -p 80 -b 0.0.0.0 VS using Nginx and Passenger?


Solution

  • There are plenty of advantages to using NGINX and Passenger for your production environment vs rails s.

    If you are using the standard WEBrick::HTTPServer for you rails s, you'll notice performance increases since NGINX and Passenger are highly optimized for this type of thing.

    NGINX provides several config files where you can control virtual hosts and use it as a reverse proxy server (http://nginx.org/en/docs/beginners_guide.html). It is extremely fast at serving static assets. As mentioned--it provides several options (load balancing, gzip options, SSL and non-secure server block setups, caching, proxying requests).

    Using NGINX with Passenger is extremely efficient as you can include Passenger in your NGINX config to automatically start your server with the set of options you need with Passenger. Passenger provides several configurations that you can use, such as, maximum/minimum amount of forked processes/threads you can have of your application and RAM limitations. Visit https://www.phusionpassenger.com/library/config/nginx/reference/ for a list of all of them. It can also restart your application when it crashes, which is also a great benefit.