带有SSL的ActionCable在生产环境中不起作用

问题描述 投票:0回答:1

我正在Rails 5.2中使用ActionCable,并在具有nginx服务器的AWS上部署了代码。以前,当我使用http时,WebSocket正常工作,但是当我实现SSL时,它便停止工作。对于SSL,我已经在AWS中实现了负载均衡器。我正在使用Unicorn作为Rails应用程序服务器。

我的ActionCable网址是:

SOCKET_URL: wss://example.com/cable
Started GET "/cable/"[non-WebSocket] for 182.74.85.106 at 2019-10-30 14:32:05 +0000
Failed to upgrade to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: )
Finished "/cable/"[non-WebSocket] for 182.74.85.106 at 2019-10-30 14:32:05 +0000

我的production.rb文件中的配置是:

config.action_cable.url = ENV["SOCKET_URL"]
ActionCable.server.config.disable_request_forgery_protection = true

我的nginx conf是:

upstream unicorn {
    server unix:/usr/share/nginx/html/demo_app/shared/tmp/unicorn.demo_app.sock fail_timeout=0;
}

server {
        listen 80;
        server_name example.com;
        root /usr/share/nginx/html/demo_app/current/public;

        try_files $uri/index.html $uri @unicorn;

        location @unicorn {
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto https;
                proxy_set_header Host $http_host;
                proxy_redirect off;
                proxy_pass http://unicorn;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "Upgrade";
        }

        error_page 500 502 503 504 /500.html;
        client_max_body_size 4G;
        keepalive_timeout 10;
}
nginx ruby-on-rails-5 unicorn actioncable
1个回答
0
投票
location /cable { proxy_pass http://unicorn/cable; 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 Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; }
© www.soinside.com 2019 - 2024. All rights reserved.