1

I have an Ionic app set up which is using the ngx-socket-io module to connect to https://my-url.co.uk.

I then have a NestJS web server set up which is setup using pm2 and has the following nginx config:

server {
    listen      %ip%:%proxy_ssl_port% ssl;
    server_name %domain_idn% %alias_idn%;
    ssl         on;
    ssl_certificate      %ssl_pem%;
    ssl_certificate_key  %ssl_key%;
    error_log  /var/log/httpd/domains/%domain%.error.log error;

    location / {
        proxy_pass      https://%ip%:3050;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;

        location ~* ^.+\.(%proxy_extentions%)$ {
            root           %sdocroot%;
            access_log     /var/log/httpd/domains/%domain%.log combined;
            access_log     /var/log/httpd/domains/%domain%.bytes bytes;
            expires        max;
            try_files      $uri @fallback;
        }
    }

        location /error/ {
                alias   %home%/%user%/web/%domain%/document_errors/;
        }

    location @fallback {
        proxy_pass      https://%ip%:3050;
    }

    location ~ /\.ht    {return 404;}
    location ~ /\.svn/  {return 404;}
    location ~ /\.git/  {return 404;}
    location ~ /\.hg/   {return 404;}
    location ~ /\.bzr/  {return 404;}

    include %home%/%user%/conf/web/snginx.%domain%.conf*;
}

The app seems to be able to connect OK, but then reverts to polling after this error:

WebSocket connection to 'wss://<my-url>.co.uk/socket.io/?EIO=3&transport=websocket' failed: Error during WebSocket handshake: Unexpected response code: 400

Is anyone able to tell me how to fix this please? I've tried all sorts of solutions I've found online but not having much luck!

Thanks for any help.

Daniel Hutton
  • 1,455
  • 1
  • 17
  • 33

0 Answers0