当尝试连接到部署在 ALB 后面的 EB 上的 Websocket 时,我收到 404 升级失败的消息。大多数与此相关的问题都没有得到解答或不清楚。
真实域名替换为 example.com
> new WebSocket('wss://example.com/cable');
WebSocket connection to 'wss://example.com/cable' failed: Error during WebSocket handshake: Unexpected response code: 404
Run Code Online (Sandbox Code Playgroud)
/var/app/current/log/Production.log 中出现错误(行已缩短)
I, Started GET "/cable"
I, Started GET "/cable/"[non-WebSocket]
E, Failed to upgrade to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: close, HTTP_UPGRADE: )
I, Finished "/cable/"[non-WebSocket]
Run Code Online (Sandbox Code Playgroud)
设置
配置/生产.rb:
config.action_cable.url = "wss://usetreasure.com/cable"
config.action_cable.allowed_request_origins = [ '/https:\/\/*/', '/http:\/\/*/' ]
Run Code Online (Sandbox Code Playgroud)
在 EB 实例上 /etc/nginx/conf.d/websockets.conf
upstream puma {
server …Run Code Online (Sandbox Code Playgroud) ruby-on-rails nginx amazon-web-services websocket amazon-elastic-beanstalk