Nginx + Unicorn + Faye Rails 4 Messaging app

Posted December 24, 2014 5.1k views

I have deployed a rails 4 application as follows:
Nginx, as a reverse proxy server
Unicorn, rails server
Now I want to add a second server, Faye, for messaging alongside with unicorn.
How I can configure nginx to accept and route requests to faye too?

My nginx default.conf file is:

upstream app { 
# Path to Unicorn SOCK file, as defined previously 
server unix:/var/homes/HS/tmp/sockets/unicorn.sock fail_timeout=0; 

server { 
listen   80; 
server_name localhost;

root /var/homes/HS/public;

try_files $uri/index.html $uri @app;

location @app { 
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
proxy_set_header Host $http_host; 
proxy_redirect off; 
proxy_pass http://app; 
error_page 500 502 422 404 /500.html; 
client_max_body_size 4G; 
keepalive_timeout 10;

I know that I need to add a location /faye block to route the request. Something like:

location /faye {

proxy_set_header Host $host; 
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
proxy_set_header X-Real-IP $remote_addr; 
proxy_connect_timeout 90; 
proxy_send_timeout 90; 
proxy_read_timeout 90; 
proxy_set_header X-Forwarded-Proto https; 


Do I have to add the; in my upstream block????? Is this enough? because my app give a connection time out.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

You aren’t using the “app” upstream in location /faye so you shouldn’t add; to the upstream block.

Your config looks proper. Is there anything listening on port 9292? Run

sudo netstat -plutn | grep 9292

and post the output.

Are you able to access the rails app directly? Try running:

curl http://localhost:9292/faye

Does that output what you expect browsing to /faye to output?