How rails app works with Unicorn and NginX? - ruby-on-rails

i would like to know how a browser request flow b/w Nginx and Unicorn to work with rails app? Explain. Thanks in advance.

Very generic question, thus a generic answer:
Nginx is usually set up as a reverse-proxy and static asset server.
Browser -(http)-> Nginx -(http)-> Unicorn worker -(rack)-> rails app
All unicorn workers share the same listening socket, balancing is done by OS via simple rule of 'first come - first serve'

Related

Running faye server with nginx and passenger?

I have successfully installed number of rails applications with nginx and passenger, but with a faye application i don't know what should be:
Nginx conf for a faye application, A nice self-explanatory tutorial will suffice.
List of things that I need to have installed to run faye server
Is it mandatory to open 443(https) port for the server and is port 9292 not needed?
Do i run faye server from rackup command in a screen or not? If no, what root do i set in nginx conf for nginx to know the start point?
How does thin server come into play? Is it needed to run?
I followed this tutorial to make my faye app. So far I have been using it through heroku, but due to latency issues I have to move to a server in the local region
Here's an example to a deployed faye app .
So far I have faye app, passenger and nginx installed on the server(centos). I am just looking for answers to above questions to proceed further. Please help Thanks in advance

Setting up multiple rails apps using nginx and Puma

I have a web server serving multiple Rails applications using a combination of nginx and Passenger. This is pretty straightforward, because the Passenger install sets-up pretty much everything you need to connect to nginx.
I found "Rails app with Puma" that seems to explain how to set up nginx and Puma together. How would this configuration need to be modified in order to serve a second Rails application on the same server?
Also, this guide doesn't say anything about restarting the application automatically if there is a system reboot or some other issue. Is there a way to do that? The nginx + Passenger combo seems to do it by default.

Using unicorn or passenger without nginx? [duplicate]

This question already has an answer here:
Is it necessary to put Unicorn behind Nginx ( or Apache)
(1 answer)
Closed 8 years ago.
I've been reading up on rails deployment and it seems for the two options I'm considering, unicorn and passenger, the tutorials always put them behind a server like nginx. I was under the assumption that both unicorn and passenger were fully functioning web servers themselves. So
Why are they always placed behind something like nginx?
If I use a load balancer nginx or HAProxy, can I have the load balancer directly distribute requests to unicorn or passenger, or do I still have to place them behind nginx?
Unicorn must be placed behind Nginx, by its author's design. The Phusion Passenger Design & Architecture document explains why some app servers are designed to be placed behind Nginx. Basically, it has got to do with I/O concurrency handling and I/O security.
Phusion Passenger however does not need to be placed behind Nginx. Phusion Passenger integrates into Nginx, as an Nginx module. Even the Standalone mode of Phusion Passenger does not need to be placed behind Nginx, because its Standalone mode utilizes a lightweight Nginx core and thus already properly implements I/O security.
If you use HAProxy, you can have it directly connect to Unicorn as long as you configure HAProxy to perform both request and response buffering. For Unicorn, buffering is key. Phusion Passenger on the other hand doesn't care, it works fine regardless of whether you configure buffering or not.

Start Unicorn using ssl in development

I'm migrating my rails app (still in development) from Thin to Unicorn. My app uses config.force_ssl = true.
When using Thin I could just write:
thin start --ssl
My question is: What is the equivalent way to start Unicorn with ssl in development?
If I correctly understood your question, you're trying to run unicorn on port 443.
This is a bad idea.
Instead, to achieve the same goal, I would suggest, run unicorn on an unprivileged port (above 1024), or better on a unix socket, and switch Nginx before, passing all static stuff directly trough nginx, and the rails stuff, trough unicorn.
I know this doesn't answer your question, but for the user, it will work exactly the same, with some benefits when your app server (unicorn) crashes, for example a nice rendered 502 error page served via nginx instead of a plain network error message seen in the browser of your users.
You can with this solution run X different applications on the same port, with different subdomains. a must have for a development machine with many projects.

find which web server rails app using

I am new to rails.
How do I find which web server rails app using?
Command to start app is
rails s puma -dp 80 -e production
Also I see apache2 is not running on server. So I guess Puma is being used. But I am not sure Puma is webserver, I found link which describes setting up Puma with nginx. So Am I using nginx? Also where do I find log of this web server?
Puma can be used as a webserver, since the command line appears to be setting the port to 80, this is probably how it is configured in your case. This works fine for the most part, but a more common configuration is to use apache or nginx as a reverse proxy and to serve static assets. (the stuff in public/assets). Requests for non-static content are then forwarded to puma.

Resources