Problems with Vscode port forwarding to localhost when using a tunnel to VPS

350 Views Asked by At

Steps to reproduce:

  1. create a ssh connection to vps using any user (root or non root)
  2. turn ssh connection into a tunnel with code tunnel
  3. now forward a port, vscode creates a url it doesn't work

What happens is you get a https://51f222222-8080.euw.devtunnels.ms/ link which is for port 8080.

So: https://<random>-<port>.<area>.devtunnels.ms/

Is it possible to get a http://localhost:8080/ forward?

So [VPS] ---(tunnel)--- [localmachine] doesn't work. So [VPS] ---(SSH)--- [localmachine] does work.

I tried connecting over SSH only to my VPS, that worked. I tried developing on my local machine (Macbook Pro M2), that worked. I tried DevContainer both on local machine as VPS via SSH, both worked.

Also, Connecting to VPN, while using Tunnel, also doesn't work.

This is Curl when it does work: curl -vk https://localhost:7080/

  • Trying 127.0.0.1:7080...
  • Connected to localhost (127.0.0.1) port 7080 (#0)
  • ALPN, offering h2
  • ALPN, offering http/1.1 ...

This is Curl when it doesn't (I close all Vscode Windows with SSH connection) curl -vk https://localhost:7080/

  • Trying [::1]:7080...
  • connect to ::1 port 7080 failed: Connection refused
  • Trying 127.0.0.1:7080...
  • connect to 127.0.0.1 port 7080 failed: Connection refused
  • Failed to connect to localhost port 7080 after 0 ms: Couldn't connect to server
  • Closing connection curl: (7) Failed to connect to localhost port 7080 after 0 ms: Couldn't connect to server
0

There are 0 best solutions below