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?
Puma is an HTTP web server derived from Mongrel and written by Evan Phoenix. It stresses speed and efficient use of memory.
Puma is a webserver that competes with Unicorn and allows you to handle concurrent requests. Puma uses threads, in addition to worker processes, to make more use of available CPU. You can only utilize threads in Puma if your entire code-base is thread safe.
Puma is a small library that provides a very fast and concurrent HTTP 1.1 server for Ruby web applications. It is designed for running Rack apps only.
"High-performance http server" is the primary reason why developers consider nginx over the competitors, whereas "Easy" was stated as the key factor in picking Puma. nginx and Puma are both open source tools. nginx with 9.1K GitHub stars and 3.43K forks on GitHub appears to be more popular than Puma with 5.78K GitHub stars and 987 GitHub forks.
I use nginx because it is very light weight. Where Apache tries to include everything in the web server, nginx opts to have external programs/facilities take care of that so the web server can focus on efficiently serving web pages.
Puma is an application server, like Passenger or Unicorn, that enables your Rails application to process requests concurrently. As Puma is not designed to be accessed by users directly, we will use Nginx as a reverse proxy that will buffer requests and responses between users and your Rails application.
Install Nginx using apt-get: Now open the default server block with a text editor: Replace the contents of the file with the following code block. Be sure to replace the the highlighted parts with the appropriate username and application name (two locations): Save and exit.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With