I previously had a Socket.io script running fine over http, but upgrading to https has broken it. I have installed the cert on the server but no luck. The code for the server setup is:
var https = require('https'),
fs = require('fs');
var options = {
key: fs.readFileSync('/etc/nginx/ssl/default/54082/server.key'),
cert: fs.readFileSync('/etc/nginx/ssl/default/54082/server.crt')
};
var app = https.createServer(options);
var io = require('socket.io').listen(app);
However in the web browser the page fails to connect to it and the console shows a the server responded with a status of 502 (Bad Gateway) response.
Any ideas on if the script set up is wrong? Or perhaps something in the Nginx setup?
Many thanks
Edit: The front end code I'm using to connect:
<script type="text/javascript" src="https://socket.example.com/socket.io/socket.io.js"></script>
<script>
var io = io('https://socket.example.com', { secure: true });
</script>
Edit:: Nginx config:
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/socket.example.co.uk/before/*;
server {
listen 443 ssl;
server_name socket.example.co.uk;
root /home/forge/socket.example.co.uk;
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/socket.example.co.uk/server/*;
location / {
proxy_pass https://socket.example.co.uk:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/socket.example.co.uk/after/*;
io.connect('<domain>:<port>',{secure:true});from the client is all you need to do to get up and running. it is not possible to proxy through nginx (and not necessary since node binds to all interfaces, and the domain is routed to your ip:port anyway due to DNS config). i literally upgraded my socket io to https yesterday without problems.var io = io('https://socket.example.com/socketio/socketio.js', { secure: true });