Code-server: Allow forwarding ports via URL

Created on 28 Jan 2020  路  10Comments  路  Source: cdr/code-server

https://github.com/cdr/code-server/issues/512

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

enhancement needs-decision

Most helpful comment

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

All 10 comments

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).

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.

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

@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.

@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.

@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.

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

@benz0li oh that's much cleaner - thanks!

It's been merged 馃帄

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pchecinski picture pchecinski  路  3Comments

infogulch picture infogulch  路  3Comments

pchecinski picture pchecinski  路  3Comments

lshamis picture lshamis  路  3Comments

korzq picture korzq  路  3Comments