3

My socket does not connect when I am using Nginx. My config file is:

server {
    listen 80;
    return 301 https://$host$request_uri;
}

server {
    listen 443;
    server_name mysite.com

    ssl     on;
    ssl_certificate      /etc/nginx/ssl/server.crt;
    ssl_certificate_key  /etc/nginx/ssl/server.key;

    ssl_protocols        TLSv1.2 TLSv1.1 TLSv1;
    ssl_prefer_server_ciphers on;
    ssl_ciphers 'kEECDH+ECDSA+AES128 kEECDH+ECDSA+AES256 kEECDH+AES128 kEECDH+AES256 kEDH+AES128 kEDH+AES256 DES-CBC3-SHA +SHA !aNULL !eNULL !LOW !MD5 !EXP !DSS !PSK !SRP !kECDH !CAMELLIA !RC4 !SEED';

    ssl_session_cache   shared:SSL:10m;
    ssl_session_timeout 10m;

    keepalive_timeout   70;

    access_log /var/log/nginx/dash.log;

    # pass the request to the node.js server
    location / {
        proxy_set_header   Host $host;
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Host $server_name;
        proxy_set_header   X-Forwarded-Proto $scheme;
        proxy_set_header X-NginX-Proxy true;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        add_header  Front-End-Https   on;

        proxy_pass         https://127.0.0.1:8081;
        proxy_redirect     off;

    }
}

My NodeJS is:

// Setup servers
var app = express();
var HTTPSOptions = {
    cert: fs.readFileSync(config.ssl.server_cert),
    key: fs.readFileSync(config.ssl.server_key),
    requestCert: false,
    rejectUnauthorized: false,
    passphrase: config.ssl.server_password
};
HTTPSOptions.agent = new https.Agent(HTTPSOptions);

io = io.listen(server, {
    log: false
});

io.sockets.on('connection', function (sock) {
    console.log("CONNECTED");
});

var httpsServer = https.createServer(HTTPSOptions, app);

And my client is

var socket = io.connect('https://localhost',  {secure: true});
socket.on('connect', function () {
    console.log("CONNECTED HERE TOO");
});

Needless to say, none of the two console.log show anything. I'm worried that nginx is blocking the request and node is actually never getting it?

3
  • Is there anything in the nginx logs? Did you make sure that calling localhost is actually matching mysite.com? any errors in the client console? Commented May 19, 2015 at 9:36
  • i have a quite similar problem....can you help me here? stackoverflow.com/questions/49210006/… Commented Mar 11, 2018 at 22:18
  • Try this solution stackoverflow.com/a/62187296/268598 Commented Jun 4, 2020 at 5:19

1 Answer 1

1

Seems like there's missing listen 443 ssl;

Sign up to request clarification or add additional context in comments.

1 Comment

i have a quite similar problem....can you help me here? stackoverflow.com/questions/49210006/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.