簡體   English   中英

使用Nginx和Unicorn,Websocket-rails不適用於生產環境

[英]Websocket-rails doesn't work on production evironment with Nginx and Unicorn

我有使用gem websocket-rails 0.7的Rails 3.2應用程序。

在開發機器上,一切正常

在生產環境中,我使用Nginx / 1.6作為代理服務器,使用Unicorn作為http服務器。 Thin用於獨立模式(遵循https://github.com/websocket-rails/websocket-rails/wiki/Standalone-Server-Mode )。

nginx配置:

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

在后端方面,我有以下代碼用於向客戶發送通知

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

在客戶端,我使用以下連接:

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

但通知不會發給客戶。

關於github的相關問題 - github.com/websocket-rails/websocket-rails/issues/211

你的nginx配置匹配/websocket/下面的請求與尾隨/ 那是/websocket/blah的目錄組件。

如果你查看你的nginx訪問日志文件,你會發現你對/websocket的請求被重定向到/websocket/

刪除尾隨/

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM