RoR 5.0.0 ActionCable wss WebSocket握手:意外的响应代码:301 [英] RoR 5.0.0 ActionCable wss WebSocket handshake: Unexpected response code: 301
问题描述
您好,我正在尝试使用ror 5.0.0 beta(与puma)进行简单的聊天 在生产模式下工作(在localhost中没有问题).
Hello I'm trying to serve a simple chat using ror 5.0.0 beta (with puma) working on production mode (in localhost there are no problems).
这是我的 Nginx 配置:
upstream websocket {
server 127.0.0.1:28080;
}
server {
listen 443;
server_name mydomain;
ssl_certificate ***/server.crt;
ssl_certificate_key ***/server.key;
ssl on;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers
HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/jenkins.access.log;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://localhost:3000;
proxy_read_timeout 90;
proxy_redirect http://localhost:3000 https://mydomain;
location /cable/{
proxy_pass http://websocket/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
break;
}
}
这是 config/redis/cable.yml
制作: 网址:redis://localhost:6379/1
production: url: redis://localhost:6379/1
发展: 网址:redis://localhost:6379/2
development: url: redis://localhost:6379/2
测试: 网址:redis://localhost:6379/3
test: url: redis://localhost:6379/3
和 config/environments/production.rb
# Action Cable endpoint configuration
config.action_cable.url = 'wss://mydomain/cable'
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = false
这是我收到的错误:
application-[...].js:27与'wss://mydomain/cable'的WebSocket连接失败:WebSocket握手期间出错:意外的响应代码:301
application-[...].js:27 WebSocket connection to 'wss://mydomain/cable' failed: Error during WebSocket handshake: Unexpected response code: 301
有什么秘诀吗? :)谢谢
Any tips? :) Thanks
推荐答案
我解决添加了乘机乘客.
nginx配置现在为:
nginx config is now :
server{
listen 80;
passenger_enabled on;
passenger_app_env production;
passenger_ruby /../ruby-2.3.0/ruby;
root /path to application/public;
client_max_body_size 4G;
keepalive_timeout 10;
[...]
location /cable{
passenger_app_group_name websocket;
passenger_force_max_concurrent_requests_per_process 0;
}
}
您必须删除默认文件夹config/redis/cable.yml并将该文件仅移动到/config.
You have to remove default folder config/redis/cable.yml and move that file to /config only.
对于SSL,只需启用默认的ssl选项即可,.-)
For SSL just enable default ssl options and it will works .-)
感谢大家的帮助
这篇关于RoR 5.0.0 ActionCable wss WebSocket握手:意外的响应代码:301的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!