Answer the question
In order to leave comments, you need to log in
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);
# 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;
}
}
Answer the question
In order to leave comments, you need to log in
https should only be on the front server, in your case on nginx
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question