Why do I need Nginx with Puma?

gylaz picture gylaz · May 24, 2018 · Viewed 7.3k times · Source

I'm deploying a Rails app to production. It seems that Puma is fast and handles many of the things I want in a web server.

I'm wondering if I even need to bother with Nginx, and what I'd be missing out on if just used Puma?

Answer

vedant picture vedant · May 24, 2018

Nginx is a web server and puma is an application server. Both have their advantages, and you need both.

Some examples:

  • Static redirects- you could setup your nginx to redirect all http traffic to the same url with https. This way such trivial requests will never hit your app server.

  • Multipart upload- Nginx is better suited to handle multipart uploads. Nginx will combine all the requests and send it as a single file to puma.

  • Serving static assets- It is recommended to serve static assets (those in /public/ endpoint in rails) via a webserver without loading your app server.

  • There are some basic DDoS protections built-in in nginx.