Назад | Перейти на главную страницу

Почему мой Nginx-Socket.io-Express-Setup не работает через HTTPS?

Локально он работает отлично, но как только я помещаю его за обратный прокси-сервер Nginx, я получаю это в консоли разработчика Chrome:

GET https://127.0.0.1:8443/socket.io/?EIO=3&transport=polling&t=MoHVP61 net::ERR_SSL_PROTOCOL_ERROR

Конфигурация Nginx:

upstream io_nodes {
  ip_hash;
  server 127.0.0.1:8443;
}

map $sent_http_content_type $expires {
    default                    off;
    text/html                  epoch;
    text/css                   max;
    application/javascript     max;
    ~image/                    max;
}

server {
    listen       80;
    listen       [::]:80;
    listen       443 ssl http2;
    listen       [::]:443 ssl http2;
    server_name  xxxxxxxxxx;
    expires      $expires;

    large_client_header_buffers 8 32k;

    error_page   404              /404.html;
    error_page   500 502 503 504  /50x.html;

    location / {
        proxy_pass http://io_nodes;
        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;
    }

    location /socket.io {
        proxy_pass http://io_nodes;
        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;
    }

    location = /404.html {
        root   /usr/share/nginx/html;
    }   
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    ssl_certificate      /etc/letsencrypt/live/thewthr.app/fullchain.pem;
    ssl_certificate_key  /etc/letsencrypt/live/thewthr.app/privkey.pem;
    include              /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam          /etc/letsencrypt/ssl-dhparams.pem;

    if ($scheme != "https") {
        return 301 https://$host$request_uri;
    }
}

Бэкэнд Socket.io:

const express = require('express');
const app = express();
const server = require('http').Server(app);
const io = require('socket.io')(server);

server.listen(process.env.PORT, () => console.log(`Express running → PORT ${server.address().port}`));

io.on('connection', () => console.log(`Socket.io running → PORT ${server.address().port}`));

Клиент Socket.io:

let socket = io.connect(`127.0.0.1:8443`);