Running unicorn and nginx on different servers

Most tutorials show how to configure nginx web server as a proxy for ruby ​​unicorn application server when it is on the same server; the result is that they both communicate over unix sockets. How to configure them if they are on different servers.

+3


source to share


2 answers


The unicorn is designed to serve fast customers only:

unicorn is an HTTP server for Rack applications designed only to serve fast clients with low latency, high speed connections, and feature advantage in Unix / Unix-like kernels. Slow clients should only be served by hosting a reverse proxy capable of fully buffering both the request and response between the unicorn and slow clients.



How does this work when load balancing across multiple host environments? The answer is to have Nginx + Unicorn application nodes (connect via Unix Domain Socket) and the top layer of Nginx as load balancing on a separate node.

+2


source


The basic setup looks like this:

In your unicorn configuration, you will need to listen on the TCP port and not the unix socket:

listen 80, :tcp_nopush => true

      



Likewise, in your Nginx configuration, just proxy requests to the remote server:

upstream backend {
    ip_hash;

    server backend1.example.com;
    server backend2.example.com;
    server backend3.example.com down;
    server backend4.example.com;
}

      

You should also check http://unicorn.bogomips.org/examples/nginx.conf for custom design nginx config.

0


source







All Articles