アプリケーションのメッセージング サービスを処理するために websocket-rails gem を使用しています。
技術スタック: Rails 4.2.5
, Ruby 2.3.0p0
, Passenger
app-server として ( も試しましたPuma
),Thin
ポート3001
のngnix
Websocket サーバーとして , Web サーバーおよび の Websocket パッチとしてgem 'websocket-rails', github: 'moaa/websocket-rails', branch: 'sync_fixes'
クライアントが Websocket サーバーにアクセスすると、サーバー イベントがアクティブにトリガーされ、印刷したメッセージでclient_connected
確認できます。websocket_rails_server.log
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++ WebsocketRails Client CONNECTED ++++++++++++++"
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
しかし、クライアント側では、応答で突然終了します。
WebSocket connection to 'ws://beta.server.com/websocket' failed: Error during WebSocket handshake: Unexpected response code: 504
Githubの問題とStackoverflow関連の質問に関するすべての解決策を試しましたが、まだ助けにはなりません.
私のnginx構成は次のとおりです(とにかく必要な場合):
server {
listen 80;
server_name beta.server.com;
root /var/www/server-rails/current/public;
proxy_cache_bypass 1;
proxy_no_cache 1;
location /websocket {
proxy_pass http://localhost:3001/websocket;
proxy_http_version 1.1;
proxy_set_header X-Real-IP $remote_addr;
add_header Access-Control-Allow-Origin *;
proxy_set_header Upgrade websocket;
proxy_set_header Connection upgrade;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
passenger_enabled on;
passenger_sticky_sessions on;
passenger_app_env staging;
}