Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I need Nginx with Puma?

Tags:

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?

like image 923
gylaz Avatar asked May 24 '18 19:05

gylaz


People also ask

Is Puma a web server?

Puma is an HTTP web server derived from Mongrel and written by Evan Phoenix. It stresses speed and efficient use of memory.

How does a Puma webserver work?

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.

Is Puma an application server?

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.

What is the difference between Nginx and Puma?

"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.

Why do people use nginx instead of Apache?

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.

What is the use of Puma in rails?

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.

How do I install nginx on Ubuntu?

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.


Video Answer


1 Answers

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.

like image 148
Vedant Agarwala Avatar answered Oct 10 '22 18:10

Vedant Agarwala