Running unicorn and nginx on different servers
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.
source to share
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.
source to share