gpt4 book ai didi

ruby-on-rails - Actioncable Nginx 和 Puma WebSocket 握手 : Unexpected response

转载 作者:数据小太阳 更新时间:2023-10-29 08:43:45 25 4
gpt4 key购买 nike

我正在尝试使用 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=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'

任何帮助将不胜感激。

最佳答案

尝试添加:

config.action_cable.allowed_request_origins = ['*']
config.action_cable.disable_request_forgery_protection = true

到你的 config/environments/production.rb 文件

它对我有用,你可以查看this link还。还有这个question

关于ruby-on-rails - Actioncable Nginx 和 Puma WebSocket 握手 : Unexpected response,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39292968/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com