Nginx, Faye, Private...trying to figure out configuration

2.2k Views Asked by At

Using Nginx 1.6 with private_pub gem Here are my config files:

private_pub.ru

# Run with: rackup private_pub.ru -s thin -E production
require "bundler/setup"
require "yaml"
require "faye"
require "private_pub"

Faye::WebSocket.load_adapter('thin')

PrivatePub.load_config(File.expand_path("../config/private_pub.yml", __FILE__),     ENV["RAILS_ENV"] || "development")
run PrivatePub.faye_app

Private_pub.yml

development:
  server: "http://localhost:9292/faye/faye"
  secret_token: "secret"
test:
  server: "http://localhost:9292/faye/faye"
  secret_token: "secret"
production:
  server: "http://xxxxx.com/faye/faye"
  secret_token: "my secret token"
  signature_expiration: 3600 # one hour

in my Nginx.conf

location /faye {
    proxy_pass http://0.0.0.0:9292;
    break;
  }

The service is running but really really slow and I get those errors on safari:

WebSocket connection to 'ws://xxxxx.com/faye' failed: Unexpected response code: 400 Failed to load resource: the server responded with a status of 404 (Not Found) Failed to load resource: the server responded with a status of 502 (Bad Gateway)

Any thoughts?

1

There are 1 best solutions below

0
On

OK.. I found the solution for those who ever want to install Faye/Private_pub on Nginx running thin and unicorn.

First:

  1. You have to understand that your upstream server is your localhost:9292 (127.0.0.1:9292)

you set your upstream in your Nginx conf by adding the following:

location /faye {

     proxy_pass http://127.0.0.1:9292;
           proxy_http_version 1.1;
           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_set_header Upgrade $http_upgrade;
           proxy_set_header Connection $connection_upgrade;
           proxy_buffering off;
           proxy_redirect off;
           proxy_connect_timeout      90;
           proxy_send_timeout         90;
           proxy_read_timeout         90;
           proxy_set_header X-Forwarded-Proto https;
           break;


  }

Also for those who have a 504 after that change the config file in the Nginx and php.fmp (if you have it) so that the timeout is increased.

Don't forget to reload your Nginx. If you still have errors check your Nginx error.log