Why do I need Nginx with Puma?

There's a significant difference between a web server and an application server. Nginx (Web Server) and Puma (App Server) will handle requests in your application simultaneously.

Whenever there's a request coming from a client, it will be received by the nginx and then it will be forwarded to the application server which is Puma over here.

Having nginx as a web server will help you in handling multiple requests much more efficiently. Being a multi threaded server it will distribute requests into multiple threads making your application more faster.

As mentioned by vendant you can serve static pages using a web server as it will be a better approach.

If you're going to include a certification to your web application then you can provide redirects from http to https over here which will hit the app server only after redirecting to https.

If you're going to use Puma then you've to make sure that server is using resources efficiently but if you'll use nginx then it's going to take care of it by itself.

you can get more info here.


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.