有一個使用 Ubunut、Nginx、Puma 和 Ruby on Rails 應用程式設定的暫存環境。它作業正常。我正在嘗試創建相同的單獨環境,但無法設定 WebSockets。我需要一些幫助來弄清楚出了什么問題,為什么 WebSocket 連接失敗。目前它顯示以下錯誤:
WebSocket connection to 'wss://upgrade.mysite.com/cable' failed: application-2c9281fcfd42a4b226b2bec3c0a6f9aaca5f7295cefd1099d252d3689e9e19d0.js:49276
Nginx 服務器配置為基本身份驗證和 SSL
以下是sites-available/mysite 中的WebSocket 配置:
upstream app {
server unix:/home/myuser/mysite/current/tmp/sockets/puma.sock fail_timeout=0;
}
server {
...
location @app {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://app;
}
location /cable {
proxy_pass http://app;
proxy_http_version 1.1;
proxy_set_header Upgrade websocket;
proxy_set_header Connection Upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
...
}
我不確定是否需要任何其他設定或如何除錯 WebSocket 連接。任何幫助表示贊賞。甚至建議如何除錯它對我來說都很重要。
ruby on rails 站點作業正常,只有 WebSocket 無法連接。部署是使用 Capistrano 完成的。
uj5u.com熱心網友回復:
問題出在config/application.rb檔案中。我已經正確設定了以下配置選項:config.action_cable.url = https://test.mysite.com但是沒有設定config.action_cable.allowed_request_origins
正確的config/application.rb檔案應如下所示:
require 'active_model/railtie'
require 'active_record/railtie'
require 'action_controller/railtie'
require 'action_mailer/railtie'
require 'action_view/railtie'
require 'action_cable/engine'
require 'sprockets/railtie'
Bundler.require(*Rails.groups)
module MyModule
class Application < Rails::Application
...
config.action_cable.url = https://test.mysite.com
config.action_cable.allowed_request_origins = [/https:\/\/test.mysite.com/]
...
end
end
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/338837.html
上一篇:是否應允許非機密客戶端應用程式使用OAuth2.0客戶端憑據流?
下一篇:由于滾動而重繪時,空集合視圖崩潰
