【问题标题】:Rails + ActionCable + Nginx + Unicorn SetupRails + ActionCable + Nginx + Unicorn 设置
【发布时间】:2017-01-07 00:18:06
【问题描述】:

我一直在尝试使用 Nginx + Unicorn 在 Ubuntu 中部署 Rails 5 + ActionCable 应用程序。

正常的http请求工作正常,但是Websockets连接被拒绝,我想是我的Nginx的问题。

我一直在 Google 中查询,发现了类似的问题和解决方案,但似乎没有任何效果:

-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

我什至尝试为 nginx 和 websockets 调整 NodeJS 设置 https://www.nginx.com/blog/nginx-nodejs-websockets-socketio/

我得到的错误是“ws://mydomain.com/cable”失败:WebSocket 握手期间出错: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;
}

}

提前致谢

【问题讨论】:

    标签: ruby-on-rails nginx unicorn actioncable


    【解决方案1】:

    像这样在我的设置中修复了类似的错误(404 in actioncable /cable)

    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;
    }
    

    【讨论】:

      猜你喜欢
      • 2018-01-06
      • 2016-07-15
      • 2013-09-15
      • 2012-11-08
      • 2016-04-13
      • 2015-11-26
      • 2015-03-28
      • 1970-01-01
      • 2017-10-02
      相关资源
      最近更新 更多