WebSocket / Socket IO on Tunnel?

Hi,

I am using my local Ubuntu machine with Cloudflared tunnel.

Trying build a WebSocket server which runs on 127.0.0.1:2095. It is proxied by Nginx from port 80, as below:

map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
}


upstream websocket{
        server 127.0.0.1:2095;
}


server{
       listen 80;
       listen [::]:80;

        server_name mydomain.com
        location ^~ /ws/ {
                proxy_pass http://websocket/;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection $connection_upgrade;
        }
}

Using wscat to test; not sure why it does not work with mydomain/com/ws/

wscat --connect ws://192.168.0.108:2095  //works fine on local network
wscat --connect ws://127.0.0.1:2095 //works fine
wscat --connect ws://mydomain.com/ws/ //error: Unexpected server response: 426

The ultimate goal is to use Socket IO on this setup. Is this possible?
When I substitute WebSocket with Socket IO, I got all errors:

wscat --connect ws://192.168.0.108:2095  //error: socket hang up
wscat --connect ws://127.0.0.1:2095 //error: socket hang up
wscat --connect ws://mydomain.com/ws/ //error: Unexpected server response: 502

I have been stuck for a while. Any help is appreciated! Thank you!!!

Tried this with a html we page. Tunnel with websockets - #4 by user1470.

Still does now work with ws://mydomain.com/ws/ or ws://ws.mydomain.com

Managed to get it work.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.