簡體   English   中英

Actioncable Nginx和Puma WebSocket握手:意外響應

[英]Actioncable Nginx and Puma WebSocket handshake: Unexpected response

我正在嘗試使用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文件

它對我有效,您也可以檢查此鏈接 這個問題

嘗試使用

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";
}

如果沒有ssl,請確保在production.rb中有config.action_cable.allowed_request_origins = [/http:\\/\\/*/, /https:\\/\\/*/]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM