6
votes

I have Rails 3.2 application with gem websocket-rails 0.7.

On development machine, all work fine

On production enviroment, I use Nginx/1.6 as proxy server and Unicorn as http server. Thin is used on standalone mode (following https://github.com/websocket-rails/websocket-rails/wiki/Standalone-Server-Mode).

nginx config:

location /websocket {
   proxy_pass http://localhost:3001/websocket;
   proxy_http_version 1.1;
   proxy_set_header Upgrade $http_upgrade;
   proxy_set_header Connection "upgrade";
}

On backend side, I have the following code for send notification to clients

WebsocketRails[:callback_requests].trigger 'new', call_request

On client side, I got a connection using:

dispatcher = new WebSocketRails window.location.host + ':3001/websocket'
channel    = dispatcher.subscribe 'callback_requests'

But notification doesn't come to the client.

Related issue on github - github.com/websocket-rails/websocket-rails/issues/211

1
did you ever resolve this issue?jay
@jay I was able to solve this problem through the use of thin as general http server, without unicorn. But for unicorn + thin(for websocket) + nginx I haven't found a solutionMaxKonin
What port were you running Nginx on? Your client code is calling 3001, but then you're proxying to 3001 as well. Nginx and Thin can't have both been serving 3001 on the same server.toxaq
Nginx is running on 80. unicorn is a socket and thin on 3001.MaxKonin

1 Answers

5
votes

Your nginx config is matching requests below /websocket/ with the trailing /. That is the directory component of /websocket/blah.

If you look in your nginx access log file you'll find your requests to /websocket are being 301 redirected to /websocket/.

Remove the trailing /

location /websocket {
   proxy_pass http://localhost:3001/websocket;
   proxy_http_version 1.1;
   proxy_set_header Upgrade $http_upgrade;
   proxy_set_header Connection "upgrade";
}