ruby-on-rails-与’ws://example.com/cable’的WebSocket连接失败:意外的响应代码:404

前端之家收集整理的这篇文章主要介绍了ruby-on-rails-与’ws://example.com/cable’的WebSocket连接失败:意外的响应代码:404 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我在Rails 5.0.0上创建了一个项目.

此外,我所做的与本视频完全相同:https://www.youtube.com/watch?v=n0WUjGkDFS0

除了生成的通道.我生成了两个渠道:聊天和评论.

我也同时阅读:https://github.com/rails/rails/tree/master/actioncable

在routes.rb中,我添加了以下行:

挂载ActionCable.server => ‘/电缆’

在application.rb中,我添加了以下行:

config.action_cable.mount_path =’/电缆’

结果,我运行了此命令的项目:

rails服务器-b SERVER_IP -p 3020

错误显示在控制台浏览器中:

WebSocket connection to ‘ws://site.com/cable’ Failed: Unexpected response code: 404

通过运行项目的一部分日志:

Started GET "/cable" for SERVER_IP at 2016-07-12 16:20:14 +0300
Cannot render console from SERVER_IP! Allowed networks: 127.0.0.1,::1,127.0.0.0/127.255.255.255
Started GET "/cable/" [WebSocket] for SERVER_IP at 2016-07-12 16:20:14 +0300
Request origin not allowed: example.com
Failed to upgrade to WebSocket (REQUEST_METHOD: GET,HTTP_CONNECTION: upgrade,HTTP_UPGRADE: websocket)
Finished "/cable/" [WebSocket] for SERVER_IP at 2016-07-12 16:20:14 +0300

错误可能是什么?我究竟做错了什么?

定义:

> SERVER_IP-这掩盖了服务器的原始IP地址.
> example.com-这掩盖了网站的原始URL.

最佳答案
确保已在development.rb文件添加了这些行

config.action_cable.url = "ws://localhost:3000/cable"

config.action_cable.allowed_request_origins = [/http:\/\/*/,/https:\/\/*/]
原文链接:https://www.f2er.com/nginx/532312.html

猜你在找的Nginx相关文章