Skip to content

Allow forwarding ports via URL #1309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nhooyr opened this issue Jan 28, 2020 · 10 comments
Closed

Allow forwarding ports via URL #1309

nhooyr opened this issue Jan 28, 2020 · 10 comments
Labels
enhancement Some improvement that isn't a feature

Comments

@nhooyr
Copy link
Contributor

nhooyr commented Jan 28, 2020

#512

So like localhost:8080/port/8080 to access port 8080 view HTTP.

@nhooyr nhooyr added the enhancement Some improvement that isn't a feature label Jan 28, 2020
@Rekrii
Copy link

Rekrii commented Jan 28, 2020

Currently I do this via a reverse proxy (nginx or similar) on the host box to forward /8080 URL to :8080 the code-server instance, and then an nginx server in CS to host whatever the user (me) wants. Very neat and simple. Not sure how scaleable it is if you needed 10k+ ports.

Comes down to if CS needs to be a swiss army knife of tools, or just a base IDE and you add stuff yourself (e.g. nginx as above).

@sr229
Copy link
Contributor

sr229 commented Jan 28, 2020

I think we'll have a lot of benefits having a port forwarding proxy since its been a long overdue request by the community for us. Though I'd prefer we do it as a VS Code extension since its more suitable to do it in VS Code's own APIs AFAIK.

@zhpengfei
Copy link

zhpengfei commented Feb 15, 2020

@Rekrii Could you share the contents of the nginx.conf ? Thanks very much!

@Rekrii
Copy link

Rekrii commented Feb 25, 2020

@zpfei206 Sorry I was on holiday. See below:

I use something simple like this in an nginx instance running in code-server:

server {
listen 8080;
server_name my.domain.com;
root /config/workspace/MyProjectHTMLFiles/;
index index.html;
}

On the nginx reverse proxy i use:

location /8080/ {
proxy_pass http://localhost:8080/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}

This way i forward a single port, 80, to my nginx RP, and it can then do basic-auth where i need (for my code-server instance) and have it hand connections to different ports internally.

Also ensure all SSL config is secure; ciphers, etc are good (I use Qualsys SSL Labs test).

As i mentioned above, this won't scale too well into a large number of ports. But I use this to test/host different prototype projects I'm working on - normally say 10 or so, so i can manually do this port forward setup for such a small number.

@benz0li
Copy link
Contributor

benz0li commented Mar 27, 2020

@Rekrii You might consider

location ~ /(\d+)/(.*) {
  proxy_pass http://localhost:$1/$2;
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection "upgrade";
}

for general port forwarding.

@kylecarbs
Copy link
Member

Fixed once #1453 is merged.

@benz0li
Copy link
Contributor

benz0li commented Mar 27, 2020

@code-asher Thanks for the great work on #1453.

I think /p/<number> would be preferable to <number>.[domain] as it remained compatibility running Code Server on Jupyter using Jupyter Server Proxy.

@code-asher
Copy link
Member

@benz0li Thanks! I didn't mention it in the PR but /proxy/<number> will also work.

@Rekrii
Copy link

Rekrii commented Mar 28, 2020

@benz0li oh that's much cleaner - thanks!

@benz0li benz0li mentioned this issue Mar 28, 2020
@kylecarbs
Copy link
Member

It's been merged 🎊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Some improvement that isn't a feature
Projects
None yet
Development

No branches or pull requests

7 participants