Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Puma without nginx - multiple ruby applications on the same IP:PORT

Nginx importance in production was normally based on its ability to serve slow clients; In the setup of RESTful API it seems to be an unnecessary layer to the production stack, especially as Puma (unlike the widely used unicorn can handle nginx work).

Puma can allow multiple slow clients to connect without requiring a worker to be blocked on the request transaction. Because of this, Puma handles slow clients gracefully. Heroku recommends Puma for use in scenarios where you expect slow clients. ref

How to enable Puma to serve multiple ruby applications on the same port without using nginx as a reverse proxy?

like image 696
I'm Mo Avatar asked Aug 07 '16 14:08

I'm Mo


1 Answers

You can't, Puma is an application server.

On the TCP/IP stack each application gets assigned to a port so that a received packet can be proxied to the application that's expecting it. Imagine that multiple applications live on the same port: There would be no way for an application to know if the receiving packet is really intended for it or for another application on the same port.

That's why we use proxies and reverse proxies. Nginx, being a reverse proxy, resolves the requested URL to an application and proxies the request to it. It's a single application that receives all incoming packets on a given port and then proxies them to an application on another port or socket.

To have multiple web servers on the same port you would have to have a reverse proxy such as Nginx or HAproxy in-front of them.

like image 120
Stanko Krtalić Rusendić Avatar answered Nov 15 '22 05:11

Stanko Krtalić Rusendić