2016-08-30 106 views
0

我一直在嘗試在Ubuntu中使用Nginx + Unicorn部署Rails 5 + ActionCable應用程序。Rails + ActionCable + Nginx + Unicorn設置

正常http請求工作正常,但Websockets連接被拒絕,我認爲是我的Nginx的一個問題。

我在谷歌一直在琢磨,發現了類似的問題和解決方案,但沒有什麼似乎工作:

- How to configure ActionCable with Nginx and Unicorn in production?

- NGINX configuration for Rails 5 ActionCable with puma

- Rails 5 Action Cable deployment with Nginx, Puma & Redis

我甚至嘗試適應的NodeJS設置爲nginx和websockets https://www.nginx.com/blog/nginx-nodejs-websockets-socketio/

我得到的錯誤是 'WS://mydomain.com/cable' 404個

upstream app_server { 
    server unix:/var/run/unicorn.sock fail_timeout=0; 
} 

server { 
    listen 80; 
    root /home/rails/rails_project/public; 
    server_name _; 
    index index.htm index.html; 

    location/{ 
     try_files $uri/index.html $uri.html $uri @app; 
} 

location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|ta$ 
       try_files $uri @app; 
     } 

location @app { 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header Host $http_host; 
     proxy_redirect off; 
     proxy_pass http://app_server; 
} 
location /cable { 
    proxy_set_header Upgrade $http_upgrade; 
    proxy_set_header Connection "upgrade"; 
    proxy_http_version 1.1; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header Host $host; 
    proxy_pass http://app_server; 
} 

} 

謝謝(在actioncable /電纜404)提前

回答

0

固定類似的錯誤在:WebSocket的握手過程中的錯誤失敗我的設置是這樣的

location /cable { 
    proxy_pass http://unix:/home/app/shared/tmp/puma/socket; 
    proxy_http_version 1.1; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header Host $http_host; 
    proxy_set_header X-Forwarded-Host $host:$server_port; 
    proxy_set_header X-Forwarded-Proto $scheme; 
    proxy_set_header Upgrade $http_upgrade; 
    proxy_set_header Connection "upgrade"; 
    proxy_read_timeout 86400; 
} 
相關問題