Using unicorn or passenger without nginx? [duplicate] - ruby-on-rails

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.

Related

Rails on Local machine with no nginx or apache

I am on the starting level of rails development. Recently i have been studying about web servers like puma, unicorn, webrick.
On the production level we need apache or nginx to handle the load balancing and processing the requests, my question is on my development machine i have no apache or nginx installed but how my rails project is working.
Thanks
Apache / Nginx serves a static files: css, js, html pages and etc.
They do it very good, and thus they're used for the production servers with high-load file traffic.
For self purpose we are need not much, thus we are satisfied with basic tools for development, such as embedded "file server" in webric or puma or unicorn.
Not make sure that I'm right, it's a kind of magic, probably somebody has more information?

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.

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.

Can someone explain to me in simple terms what Passenger is?

I was researching to set up my linux (ubuntu) vps for rails. And almost all of the guides I've read tells me to install passenger. But none of the guides explain what it is (atleast not in simple terms). So I was wondering if someone could explain in simple terms what exactly passenger is.
I'm trying to set up my VPS so I can easily push code to it from git, and deploy my app (Easy as heroku?) Any suggestions?
Your web server (apache/nginx) serves HTTP requests for files, like stylesheets and images. But, it doesn't know how to process programming code. In PHP, for example, you have to enable mod_php to allow PHP to run.
Passenger is to ruby/rails what mod_php is to PHP.
Your web server still serves static files, but has passenger run your ruby code.
Passenger usually works with Apache/nginx.
Passenger does the dynamic things, Apache/nginx serves
static files and helps passenger to communicate with user-agents
mod passenger or phusion passenger is a module to deploy ruby on rails application in nginx or apache . Currently you must be using either web brick or mongrel. using mod passenger you can have the full power of nginx or apache at your disposal,

Rails framework & Nginx web server

As we install rails it uses its own web server WEBrick. If i want to run ths application in Nginx server, then how to configure or set the Nginx web werver?
You should run your rails application in a production server such as mongrel_cluster or thin (I have used the former, and am currently switching to the latter). To put nginx in front of it, I would use the upstream and proxy_pass directives. I found a nice blog post comparing ways of running rails applications that shows their config for mongrel_cluster + nginx.
Passenger is also available for nginx, I've used that with Apache and it was very easy to set up.

Resources