2

I'm trying to setup my SocketCluster app to use SSL. I'm able to get it working on nginx without ssl but not with it. When ever I visit the site in the browser I get the nginx welcome page. If i visit port 8000 in the browser I'm able to see socket cluster but not if using the https protocol.

nginx config

server {
    listen 443;

    ssl on;
    ssl_certificate /etc/ssl/server.crt;
    ssl_certificate_key /etc/ssl/server.key;

    server_name 104.xxx.54.xxx;
    access_log /var/log/nginx/nginx.vhost.access.log;
    error_log /var/log/nginx/nginx.vhost.error.log;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header HOST $http_host;
        proxy_set_header X-NginX-Proxy true;

        proxy_pass https://localhost:8000;
        proxy_redirect off;
    }
}

server.js

var argv = require('minimist')(process.argv.slice(2));
var SocketCluster = require('socketcluster').SocketCluster;
require('dotenv').config();

var socketCluster = new SocketCluster({
  workers: Number(argv.w) || 3,
  brokers: Number(argv.b) || 1,
  port: Number(argv.p) || 8000,
  path: '/socket',
  appName: '...',
  workerController: __dirname + '/worker.js',
  brokerController: __dirname + '/broker.js',
  socketChannelLimit: 1000,
  crashWorkerOnError: argv['auto-reboot'] != false,
  rejectUnauthorized: false,
  secure: true
});
Antarr Byrd
  • 24,863
  • 33
  • 100
  • 188
  • doesn't your ssl port have to be 8000 as well not just default 443 and proxy pass for 8000. – Dave Mar 10 '16 at 16:41
  • @Dave I'm don't have the best understanding of nginx. What I want it to do is to render port 8000 when you visit 433 externally. – Antarr Byrd Mar 10 '16 at 16:44

1 Answers1

2

You appear to be terminating SSL in the reverse-proxy. Your service listening on port 8000 is non-SSL. So your proxy-pass should use HTTP for the upstream connection and not HTTPS. Try:

proxy_pass http://localhost:8000;

You may want to add an X-Forwarded-Proto header:

proxy_set_header X-Forwarded-Proto $scheme;
Richard Smith
  • 45,711
  • 6
  • 82
  • 81