使用nginx和ssl配置SocketCluster

时间:2016-03-10 16:38:16

标签: ssl nginx socketcluster

我试图设置我的SocketCluster应用程序以使用SSL。我能够在不使用ssl的情况下使用nginx但不能使用它。当我在浏览器中访问该网站时,我得到了nginx欢迎页面。如果我在浏览器中访问端口8000,我可以看到套接字群集,但如果使用https协议则不能。

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

1 个答案:

答案 0 :(得分:1)

您似乎在反向代理中终止SSL。在端口8000上侦听的服务是非SSL的。因此,您的proxy-pass应该使用HTTP进行上游连接,而不是HTTPS。尝试:

proxy_pass http://localhost:8000;

您可能需要添加X-Forwarded-Proto标题:

proxy_set_header X-Forwarded-Proto $scheme;