openvscode-server icon indicating copy to clipboard operation
openvscode-server copied to clipboard

Port forwarding feature via subdomain/path

Open adyanth opened this issue 4 years ago • 7 comments

Is it possible to provide port forwarding feature that native VS Code provides?

The Coder web version of VS Code also provides this here: https://coder.com/docs/code-server/latest/guide#accessing-web-services-1

The above linked service does it by proxying all requests to <port>.somesubdomain.com to the application running on that port in the container. Another way it provides is <url_to_access_vscode_online>/proxy/<port>.

adyanth avatar Oct 02 '21 14:10 adyanth

  • The goal of the project to keep up minimal set of changes to provide the compatible server. Adding such features goes against it.
  • Exposing ports on the same origin where IDE is running is not really great idea. IDE holds your secrets in browser caches, websites running on ports in suggested way will be able to access it. I would make sure that they run on different origin at least.

akosyakov avatar Oct 04 '21 08:10 akosyakov

But the actual VSCode provides that feature of port forwarding when connected to remote hosts, which really cannot be replicated when running it as a server from the browser in any other way. And it is helpful.

As you said, running it on a different origin is good (can be configurable too as in Coder), and those sites are what the users themselves run in a dev environment. So either way it is upto the user to take care of that.

adyanth avatar Oct 04 '21 10:10 adyanth

fyi, we implemented that feature via an nginx trick in our SWAG reverse proxy. We simply use a named group in the server_name regex to capture the port as a var, and use that var in the proxy_pass directive: https://github.com/linuxserver/reverse-proxy-confs/blob/master/openvscode-server.subdomain.conf.sample#L74

aptalca avatar Nov 30 '21 02:11 aptalca

That's a brilliant idea. I forgot we could get the reverse proxy to do it. Thanks! I wonder if Traefik can do that without a custom middleware.

adyanth avatar Nov 30 '21 05:11 adyanth

I think there are a couple of possible duplicate issues: #320 and to some extent #163

The mentioned workaround by @aptalca works using an additional prefix rather than a subpath. Could we get it to work with a subpath, too?

Something along the lines of:

server {
    listen 8888;
    listen [::]:8888;

    server_name example.com;

    location /code/ {
        proxy_set_header    X-Real-IP  $remote_addr;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header    Host $http_host;
        proxy_redirect      off;
        rewrite             ^/code/(.*) /$1 break;
        proxy_pass          http://127.0.0.1:3000;
    }

    location /code {
        return 301 /code/;
    }
}

where we should get it running on example.com:8888/code. That doesn't work though, but I've got no clue if this is at all possible with only an NGINX configuration.

TiemenSch avatar Nov 29 '22 15:11 TiemenSch

#320

has anyone had success with this?

rohrig avatar Feb 21 '23 20:02 rohrig

https://github.com/gitpod-io/openvscode-server/issues/336#issuecomment-2059566637

in case, using dynamic port expose with docker container, using reverse proxy by nginx

Fhwang0926 avatar Apr 16 '24 17:04 Fhwang0926