[英]Rails 5 Error during WebSocket handshake: Unexpected response code: 502
我在 Rails 應用程序中使用 web-socket:使用 Rails 5.2.3、ruby 2.4.0p0,我的 websocket 正在通過 http 查找,但是當我切換到 https 時出現以下錯誤。 錯誤如下:
與“wss://tukaweb.com/cable”的 WebSocket 連接失敗:WebSocket 握手期間出錯:意外響應代碼:502
我曾嘗試將 production.rb 中的配置更改為
config.action_cable.url = 'wss://tukaweb.com/cable'
config.action_cable.allowed_request_origins = [ 'http://tukaweb.com', /http:\/\/tukaweb.*/ ]
和
config.action_cable.url = [/ws:\/\/*/, /wss:\/\/*/]
config.action_cable.allowed_request_origins = [/http:\/\/*/, /https:\/\/*/]
還添加了動作電纜元標記:
<%= action_cable_meta_tag %>
但是錯誤仍然存在,任何人都可以建議正確的配置,謝謝,以及為什么它可以在 http 測試台環境中正常工作,但在 https 和 ssl 上出現錯誤。 我還使用帶有乘客模塊的 Nginx 服務器來運行 Rails 環境。
將 /home/vidur/Downloads/tukaweb/app/assets/javascripts/cable.js 更新為:
//= require action_cable
//= require_self
//= require_tree ./channels
(function() {
this.App || (this.App = {});
App.cable = ActionCable.createConsumer("/cable");
}).call(this);
生產.rb到:
config.action_cable.url = "/cable"
config.action_cable.allowed_request_origins = [ 'http://52.35.24.20','http://tukaweb.com', 'https://tukaweb.com' ]
路由.rb到:
mount ActionCable.server => '/cable'
cable.yml 到:
development:
adapter: redis
url: redis://localhost:6379/1
test:
adapter: async
production:
adapter: redis
url: redis://localhost:6379/1
將虛擬主機更新為:
location /cable {
passenger_app_group_name tukaweb_action_cable;
passenger_force_max_concurrent_requests_per_process 0;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.