Ruby on rails Actioncable Nginx和Puma WebSocket握手:意外响应
我正在尝试用rails 5、Nginx和Puma配置服务器。应用程序运行良好,但Actioncable正在提供Ruby on rails Actioncable Nginx和Puma WebSocket握手:意外响应,ruby-on-rails,ruby,nginx,puma,actioncable,Ruby On Rails,Ruby,Nginx,Puma,Actioncable,我正在尝试用rails 5、Nginx和Puma配置服务器。应用程序运行良好,但Actioncable正在提供 WebSocket connection to 'ws://server_name.com/cable' failed: Error during WebSocket handshake: Unexpected response code: 200 下面是我的nginx设置 upstream app { server unix:/tmp/app.sock fail_timeout
WebSocket connection to 'ws://server_name.com/cable' failed:
Error during WebSocket handshake: Unexpected response code: 200
下面是我的nginx设置
upstream app {
server unix:/tmp/app.sock fail_timeout=0;
}
server {
listen 80;
server_name server_name.com;
try_files $uri/index.html $uri @app;
client_max_body_size 100M;
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app;
client_max_body_size 10M;
}
location /cable {
proxy_pass http://app/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
location ~ ^/(assets|uploads)/ {
root assets_path;
gzip_static on;
expires max;
add_header Cache-Control public;
add_header ETag "";
break;
}
error_page 500 502 503 504 /500.html;
}
在production.rb中的rails中,我做了如下设置
config.action_cable.url = 'ws://server_name.com/cable'
任何帮助都将不胜感激 尝试使用
location /cable {
proxy_pass http://app; # not http://app/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
并且还要确保您的production.rb中有config.action\u cable.allowed\u request\u origins=[/http:\/\/*/,/https:\/\/*/]
,如果您没有ssl,请尝试添加:
config.action_cable.allowed_request_origins = ['*']
config.action_cable.disable_request_forgery_protection = true
到您的config/environments/production.rb
文件
它和我一起工作,你也可以检查。
这试着使用
ws://server\u name.com/cable/websocket
这不是工作伙伴。你找到解决方法了吗?我也被这件事缠住了。