Bad Gateway Error using Socket.io Node.js over SSL
<p>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:</p>

<pre><code>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);
</code></pre>

<p>However in the web browser the page fails to connect to it and the console shows a <code>the server responded with a status of 502 (Bad Gateway)</code> response.</p>

<p>Any ideas on if the script set up is wrong? Or perhaps something in the Nginx setup?</p>

<p>Many thanks</p>

<p><strong>Edit:</strong> The front end code I'm using to connect:</p>

<pre><code>&lt;script type="text/javascript" src="https://socket.example.com/socket.io/socket.io.js"&gt;&lt;/script&gt;
&lt;script&gt;
var io = io('https://socket.example.com', { secure: true });
&lt;/script&gt;
</code></pre>

<p><strong>Edit::</strong> Nginx config:</p>

<pre><code># 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/*;
</code></pre>