Gần đây tôi đã chuyển dự án đường ray từ Rails4 thành 5.0.0.beta3 để sử dụng ActionCable tuyệt vời.Làm thế nào để cấu hình ActionCable với Nginx và Unicorn trong sản xuất?
Máy chủ ActionCable của tôi chạy bên trong lân. Trong phát triển tất cả các công trình tốt. Trong sản xuất tôi có
Started GET "/cable" for xxx.xxx.xxx.xxx at 2016-03-28 18:06:38 +0300
Started GET "/cable/" [WebSocket] for xxx.xxx.xxx.xxx at 2016-03-28 18:06
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
Registered connection (189772ff-6229-48f1-ae7f-d9a96ad3a6c3)
Finished "/cable/" [WebSocket] for xxx.xxx.xxx.xxx at 2016-03-28 18:06:35
Và thông báo này lặp đi lặp lại lặp đi lặp lại.
Tôi đã thử nhiều tùy chọn ở ngăn xếp để xử lý việc này nhưng không có gì hữu ích. nginx cấu hình của tôi:
upstream unicorn {
server unix:/tmp/unicorn.my_app.sock fail_timeout=0;
}
server {
server_name www.my_app.com;
return 301 $scheme://my_app.com$request_uri;
}
server {
listen 80 default deferred;
server_name my_app.com;
root /var/www/my_app/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}
location /cable {
proxy_pass http://unicorn/cable;
proxy_http_version 1.1;
proxy_set_header Upgrade websocket;
proxy_set_header Connection Upgrade;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
error_page 500 502 503 504 /500.html;
keepalive_timeout 5;
}
Để chắc chắn rằng yêu cầu được phép tôi đã tạm thời sử dụng mã này trong initializers: ActionCable.server.config.disable_request_forgery_protection = true
tập tin cable.coffee
My
@App ||= {}
App.cable = ActionCable.createConsumer "/cable"
tập tin config/cable.yml
My
production:
adapter: redis
url: redis://localhost:6379/1
Tôi không quá kinh nghiệm về câu hỏi này, vì vậy mọi trợ giúp sẽ rất tuyệt vời.
Bạn có 'mount ActionCable.server => '/ cable'' trong tuyến đường của mình không? – siegy22
@yzalavin Bạn có thể giải quyết vấn đề này không? Tôi thấy cùng một vấn đề. –
@R_G Tôi cũng gặp vấn đề tương tự. Bạn có thể tìm thấy sự cố không? Từ những gì tôi đã gỡ lỗi unicorn là không thể gửi ping cho khách hàng và do đó, khách hàng đang cố gắng kết nối lại. Vì vậy, các câu lệnh kết nối trong vòng lặp. Không chắc chắn lý do tại sao luồng theo hướng khác không hoạt động – sethi