1

I have a React app communicating with a very simple node backend, it works perfectly fine in local and was working perfectly fine over http. For obvious reason, the app is now running in https but the socket is not connecting anymore. I have been looking to so many threads but couldn't find a way to fix it. Here are the socket parts of my code and nginx conf.

Client side:

const socket = io('wss://sub.domain.io', { path: '/my-path',});

Server side:

const server = require('http').createServer();

const io = require('socket.io')(server, {
    path: '/my-path',
    serveClient: false
});

server.listen(8080);

nginx proxy

server {
      ....website serving part...

      location /my-path/ {
        proxy_pass http://localhost:8080;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
    }
 }

Error is: GET https://sub.domain.io/my-path/?EIO=3&transport=polling&t=MsCot3e net::ERR_CONNECTION_TIMED_OUT VM17:1 which looks like a timeout because it fails to connect.

1
  • Removing React tag as there's no react code in the question. Commented Oct 2, 2019 at 14:31

1 Answer 1

1

So I found an answer after so many hours and it is pretty dumb and simple. My Nginx only handle the www website (DNS redirection is enough for the website), hence I needed www.sub.domain.io here:

const socket = io('wss://www.sub.domain.io', { path: '/my-path',});
Sign up to request clarification or add additional context in comments.

Comments

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.