【发布时间】:2019-11-26 16:52:12
【问题描述】:
我在 Digital Ocean 上有 Rails 应用程序(Ununtu 18.04 + nginx +passenger + Capistrano)。我的应用程序中有基于 Action Cable 的聊天功能。在我的本地,一切正常,但在生产中我得到下一个错误:Error during WebSocket handshake: Unexpected response code: 502.
据我了解,Action Cable 配置有问题。但是一切都在教程中完成,所以我现在真的很困惑,不知道我应该在哪里寻找邪恶。请帮忙!
production.rb 文件
config.action_cable.url = '/cable'
config.action_cable.allowed_request_origins = ['http://example.com']
cable.yml 文件
production:
adapter: redis
url: redis://redis.exmaple.com:6379
messages.coffee 文件
jQuery(() ->
App.messages = App.cable.subscriptions.create {channel: 'MessagesChannel', id: $('#conversation_id').val() },
received: (data) ->
jQuery('#new_message')[0].reset()
jQuery('#chat').append data.message
)
messages_channel.rb 文件
class MessagesChannel < ApplicationCable::Channel
def subscribed
stream_from "conversation_#{params[:id]}"
end
end
/etc/nginx/sites-enabled/myapp 文件
server {
listen 80;
listen [::]:80;
server_name example.com;
root /home/deploy/myapp/current/public;
passenger_enabled on;
passenger_app_env production;
location /cable {
passenger_app_group_name myapp_websocket;
passenger_force_max_concurrent_requests_per_process 0;
}
# Allow uploads up to 100MB in size
client_max_body_size 100m;
location ~ ^/(assets|packs) {
expires max;
gzip_static on;
}
}
在 nginx 中我有很多这样的错误:
2019/07/18 07:37:47 [error] 25500#25500: *9088 upstream prematurely closed connection while reading response header from upstream, client: 117.102.40.105, server: example, request: "GET /cable HTTP/1.1", upstream: "passenger:unix:/tmp/passenger.q4FqjUT/agents.s/core:", host: "example.com"
当然,example.com 到处都是我的真实域名。
【问题讨论】:
-
请发布任何相关代码以及错误本身:)
-
并包含您的 nginx 错误日志中的任何相关消息。
标签: ruby-on-rails nginx websocket