S
S
SvizzZzy2017-02-12 13:42:34
Node.js
SvizzZzy, 2017-02-12 13:42:34

How to configure socket.io for https?

Hello.
Trying to get socket.js to work over https.
Everything works with the settings for HTTP and through the server IP (I have a VPS) via HTTPS, but it doesn’t work through a subdomain that has HTTPS.
Settings like this:
Run nodejs script:

var fs = require('fs');
var https = require('https');

var options = {
    key: fs.readFileSync('/var/www/httpd-cert/site/айписервера.key'),
    cert: fs.readFileSync('/var/www/httpd-cert/site/айписервера.crt')
};

server = https.createServer(options);
var io = require('/usr/local/lib/node_modules/socket.io').listen(server);
server.listen(900);

And nginx.conf:
# in the http{} configuration block
upstream socket_nodes {
    ip_hash;
    server io.domain:900 weight=5;
    server io.domain:900;
    server io.domain:900;
    server io.domain:900;
}

server {
    server_name io.domain.com;
    location / {
        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://socket_nodes;
    }
}

At startup, "infinite waiting" begins on https://io.domain:900 and https://io.domain:900/socket.io/socket.io.js
And as I wrote above, on ip vps: https: //ipvps:900 and https://io.ipvps:900/socket.io/socket.io.js everything works...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Belyaev, 2017-02-12
@SvizzZzy

https should only be on the front server, in your case on nginx

E
Eugene, 2017-02-12
@Nc_Soft

proxy_pass http://socket_nodes;
You need either socket.io via http to work, or proxy to httpS://socket_nodes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question