ruby-on-rails - ActonCable 不适用于产品(Rails5 + Redis + Nginx + SSL)
问题描述
在我的应用程序中,我有一个 ActionCable 在本地运行良好,但不能强制它在生产服务器上运行。
我的堆栈是:
- 导轨 5.2
- Ubuntu 18.04
- 雷迪斯
- NGINX 和乘客
资产/javascripts/channels/index.coffee
App.cable = ActionCable.createConsumer("/cable")
- 电缆.js
(function() {
this.App || (this.App = {});
App.cable = ActionCable.createConsumer("/cable")
}).call(this);
- 路线:
mount ActionCable.server => "/cable"
- 配置/环境/production.rb
config.action_cable.allowed_request_origins = [/http:\/\/*/, /https:\/\/*/]
- nginx 站点启用/我的应用程序
server{
server_name subdomain.my-app.app;
passenger_enabled on;
rails_env production;
root /home/deploy/my-app/current/public;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/iris.gemisoft.app/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/iris.gemisoft.app/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
# REDIS / ACTIONCABLE
location /cable {
passenger_app_group_name subdomain_my-app_app_websocket;
passenger_force_max_concurrent_requests_per_process 0;
}
}
server {
# if ($host = subdomain.my-app.app) {
# return 301 https://$host$request_uri;
# } # managed by Certbot
listen 80;
listen [::]:80 ipv6only=on;
server_name subdomain.my-app.app;
#return 404; # managed by Certbot
}
Expected behaviour: When Admin click a button, users gets a message.
Current behaviour (on prod): When admin clicks a button, nothing happens, in redis console i can see:
1559571365.936128 [1 127.0.0.1:53530] "publish" "test" "{\"message\":\"message\"}"
更新:cable.yml:
development:
adapter: redis
url: redis://localhost:6379/1
test:
adapter: redis
url: redis://localhost:6379/1
production:
adapter: redis
url: redis://localhost:6379/1
解决方案
我找到了解决方案。在我的设置中,我同时拥有 jquery_ujs 和 rails-ujs。通过删除 jquery_ujs 解决了问题。
推荐阅读
- python - 我的代码没有在 IntelliJ python 中返回。为什么不回来?我知道有一个基本原因
- android - ios中的标签栏位于屏幕顶部
- python - Python从复杂字典创建子字典
- django - 在Django中选择文件后预览照片
- git - 修改先前提交的实际代码文件(c#、java 等)(使用 git)?
- ruby - cancancan的多级授权
- javascript - 棋盘Java脚本建议需要
- serialization - 使用协议缓冲区序列化/反序列化对象
- c# - 如何通过查询旧列表 c# 中的最新文件来填充新列表?
- sql-server - 使用 WITH (READPAST, ROWLOCK, XLOCK) 优化 Select-then-update 模式的并发解决方案