【问题标题】:ActionCable 404 error for wss with ELB and nginx带有 ELB 和 nginx 的 wss 的 ActionCable 404 错误
【发布时间】:2017-09-06 00:51:01
【问题描述】:

当我将网站切换到 https 时,我收到了 actioncable 错误:

WebSocket connection to 'wss://domain.com/cable' failed: Error during WebSocket handshake: Unexpected response code: 404

https 网站工作正常,但我得到一个 404 的 websocket 地址。我当前的设置使 SSL 在 ELB 处终止,并且 nginx 将 http 重定向到 https。我将 actioncable 与我的铁路服务器一起运行,而不是作为独立服务器运行。

如何在 中设置安全的 websocket?

这是我的 nginx 配置文件

upstream puma {
  server unix://var/run/server.sock;
}

server {
  listen 80;
  server_name default_server;

  root /var/www/apps/server/public;

  location /cable {
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    proxy_pass http://puma;
  }

  location / {
    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;
    proxy_redirect off;
    proxy_next_upstream error;

   if ($http_x_forwarded_proto != "https") {
     rewrite ^(.*)$ https://$host$1 permanent;
   }

  proxy_pass http://puma;

  ...

}

这是ELB上的配置:

ELB Listeners

【问题讨论】:

标签: ssl nginx amazon-elb actioncable


【解决方案1】:

像这样在我的设置中修复了类似的错误(404 in actioncable /cable)

location /cable {
    proxy_pass http://unix:/home/app/shared/tmp/puma/socket;
    proxy_http_version 1.1;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Host $host:$server_port;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_read_timeout 86400;
}

所以添加与其他 location 相同的 proxy_set_header(X-Real-IP 等)

【讨论】:

    猜你喜欢
    • 2017-10-02
    • 2022-07-27
    • 2019-05-03
    • 1970-01-01
    • 1970-01-01
    • 2016-04-13
    • 2017-09-24
    • 2021-03-09
    • 1970-01-01
    相关资源
    最近更新 更多