尝试使用ActionCable时,Rails 5.0.0.beta2中的应用程序出现服务器问题.
使用localhost:3000可以正常工作,因为这是大多数ActionCable默认的.但是,如果我尝试在端口3001上运行rails服务器,它会给我Request origin not allowed: http://localhost:3001
ActionCable文档提到使用类似的东西ActionCable.server.config.allowed_request_origins = ['http://localhost:3001']
,如果我把它放入其中对我有用config.ru
但这似乎是一个非常奇怪的地方.我觉得它应该能够进入初始化文件或我的development.rb环境配置文件.
为了进一步证明我应该允许它进入那里,该设置ActionCable.server.config.disable_request_forgery_protection = true
可以忽略请求源,即使我将它包含在development.rb中也是如此.
为什么会ActionCable.server.config.disable_request_forgery_protection
在development.rb中工作,但ActionCable.server.config.allowed_request_origins
不能(但在config.ru中工作)?
这不是一个紧迫的问题,因为我有几种选择作为解决方法.我只是想知道我是否遗漏了一些明显的关于我认为这应该如何工作的东西.
已经通过 Capistrano 部署了我的 Rails 5.2 应用程序,并且在使用 ActionCable 时遇到了问题。我正在使用 Nginx、Puma 和 Lets Encrypt。
我尝试了多种配置组合,但每次都收到相同的错误。我不知道如何调试这个问题,建议以及重新安排我的 ngnx.conf 的任何提示都会受到赞赏。
已将真实网站更改为 website.com
配置文件
upstream puma {
server unix:///home/deploy/apps/website/shared/tmp/sockets/website-puma.sock;
}
server {
server_name website.com www.website.com;
root /home/deploy/apps/website/current/public;
index index.html;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @puma;
location @puma {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://puma;
}
location /cable {
proxy_pass http://puma;
proxy_http_version 1.1;
proxy_set_header Upgrade websocket;
proxy_set_header Connection Upgrade;
proxy_set_header X-Real-IP …
Run Code Online (Sandbox Code Playgroud)