0
votes

I have an chat application deployed to a vps with Puma and Nginx 1.10 my nginx config is the following:

upstream websocket {
  server 127.0.0.1:28080;
}

server {
  location /cable {
    proxy_pass http://websocket/;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
  }
}

This is my config.ru file for cable:

require ::File.expand_path('../../config/environment',  __FILE__)
Rails.application.eager_load!

ActionCable.server.config.disable_request_forgery_protection = true

run ActionCable.server

In environment/production.rb

config.action_cable.allowed_request_origins = ['http://ahu.mydomain.ir', 'https://ahu.mydomain.ir']
config.action_cable.url = "ws://ahu.mydomain.ir/cable"

My client connected to internet via a proxy server and in chrome console i get the following error:

WebSocket connection to 'ws://ahu.mydomain.ir/cable' failed: Establishing a tunnel via proxy server failed

In another client without proxy every thing is OK.

1

1 Answers

0
votes

Fortunately I found answer, We should add SSL to VPS and set Nginx config to use that by port 443.

To use SSL we should add the following in Nginx .conf file:

server {
        listen       443 ssl;
        server_name  YOUR_SERVER;
        ssl on;
        ssl_certificate /path/to/FILE.crt;
        ssl_certificate_key /path/to/FILE.key;
    }