websocket-rails: Websocket-rails doesn't work on production evironment with Nginx ang Unicorn
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. 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.
About this issue
- Original URL
- State: open
- Created 10 years ago
- Comments: 35 (2 by maintainers)
Solved!
Nginx:
javascript, i have to change to false to use http:
var websocket = new WebSocketRails(window.location.hostname + '/websocket', false);Try to set location like below:
Here is my nginx config
And the connection to ws is made like this
ws://example.com/websocketAlso by default config.force_ssl is always false. So If its commented out, it should be fine.
Let me know if that helps.
It’s a long shot, but if i remember correctly. Some version of nginx are case sensitive on the “Upgrade” section.
Here’s a copy and paste from an app I have in production.