Ryz*_*off 6 ruby-on-rails passenger websocket ruby-on-rails-5 actioncable
我正在尝试将ActionCable和Rails 5部署到生产服务器(DigitalOcean).我已按照Gorails视频中提到的所有步骤进行操作:https://gorails.com/episodes/deploy-actioncable-and-rails-5
该应用程序使用Phusion Passenger + Nginx + Capistrano进行部署.
当我尝试在生产中检查我的网站时,我在浏览器的控制台上收到了此错误:
WebSocket connection to 'ws://139.59.175.34/cable' failed: Error during WebSocket handshake: Unexpected response code: 404
这些是我的设置:
在/ etc/nginx的/启用的站点 - /默认
server {
listen 80;
listen [::]:80 ipv6only=on;
server_name my_server_domain;
passenger_enabled on;
rails_env production;
root /home/deploy/my_app_domain/current/public;
# ActionCabel config (disable this if u r not using it)
location /cable {
passenger_app_group_name actioncable_websocket;
passenger_force_max_concurrent_requests_per_process 0;
}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
Run Code Online (Sandbox Code Playgroud)
production.rb
config.action_cable.url = "/cable"
config.action_cable.allowed_request_origins = ["http://139.59.175.34"]
Run Code Online (Sandbox Code Playgroud)
cable.js
(function() {
this.App || (this.App = {});
App.cable = ActionCable.createConsumer("/cable");
}).call(this);
Run Code Online (Sandbox Code Playgroud)
我试图将ActionCable配置更改config/production.rb
为:
config.action_cable.url = [/ws:\/\/*/, /wss:\/\/*/]
config.action_cable.allowed_request_origins = [/http:\/\/*/, /https:\/\/*/]
Run Code Online (Sandbox Code Playgroud)
但仍然没有运气.
我也查看了服务器上的production.log,这是记录的错误:
WebSocket error occurred: One or more reserved bits are on: reserved1 = 1, reserved2 = 0, reserved3 = 0
Run Code Online (Sandbox Code Playgroud)
更新:
以下是服务器上的防火墙设置:
最后我找到了我的问题的答案。原来我的生产服务器上没有安装redis。所以我只需要安装 redis,现在一切都很好!
要检查服务器上是否安装了redis,请使用以下命令:
redis-cli
如果出现 redis 控制台,则一切就绪。如果出现错误/警告,您可以按照以下步骤安装并运行redis:
sudo apt install redis-server
redis-server
希望能帮助到你!
归档时间: |
|
查看次数: |
762 次 |
最近记录: |