gitpod-io / openvscode-server

Run upstream VS Code on a remote machine with access through a modern web browser from any device, anywhere.
https://www.gitpod.io/
MIT License
5.07k stars 440 forks source link

Web Socket error #336

Open arita37 opened 2 years ago

arita37 commented 2 years ago

Steps to Reproduce:

  1. docker run -it --init -p 3000:3000 -v "$(pwd):/home/workspace:cached" gitpod/openvscode-server
  2. open the URL in the browser.

At open, it days Web Socker error.

It seems the UI tries to communicate with some backend executable using some sockets. My server is a secure one, socket communication are restricted.

But, Jupyterlab works well

related to this one: https://stackoverflow.com/posts/71303474/timeline)0](https://stackoverflow.com/questions/68799580/vscode-cannot-connect-to-remote-linux-websocket-close-with-status-code-1006

If anyone else comes across this question it's very easy.

You're most likely using a reverse proxy
Just enable websocket support on your reverse proxy.
Ex. If you are using Docker and the popular NGINX Proxy Manager; when you are adding a proxy host make sure to choose websocket support

No more 1006 error :)

also this topic: https://github.com/gitpod-io/openvscode-server/issues/163

Antjrobles commented 2 years ago

Hi arita37, I have vscode running behin nginx proxy manager, and of course I have enable websocket support on my reverse proxy, but still wont work. Do you fixed this only by enabling this option?. Thanks

idc77 commented 2 years ago
server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;

        server_name vsc.example.com *.vsc.example.com;

        ssl_certificate /etc/letsencrypt/live/vsc.example.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/vsc.example.com/privkey.pem;

        error_log /var/log/nginx/vsc.example.com.error.log;
        access_log /var/log/nginx/vsc.example.com.access.log;

        location / {
                proxy_pass http://unix:/home/vsc/tmp/vsc.sock;
                proxy_read_timeout 10;
                proxy_connect_timeout 10;
                proxy_redirect off;
                proxy_set_header X-Real-IP          $remote_addr;
                proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto  $scheme;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
        }

       location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;
                proxy_pass http://unix:/home/vsc/tmp/vsc.sock;
                proxy_read_timeout 10;
                proxy_connect_timeout 10;
                proxy_redirect off;
                proxy_set_header X-Real-IP          $remote_addr;
                proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto  $scheme;
       }
}
Fhwang0926 commented 7 months ago

in my case need dynamic port expose for docker conatainer, so using reverse proxy with nginx

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

server {
    listen 443 ssl;
    server_name ide.example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/cert.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_prefer_server_ciphers on;

    add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';

    resolver localhost:53;

    include /etc/nginx/mime.types;
    types {
        application/wasm wasm;
    }

    location ~ /port/(\d+)/stable-(.*) {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:$1/stable-$2;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        add_header Set-Cookie "port=$1; Path=/";
    }

    location ~ /stable-(.*)/static/(.*) {
        set $port $cookie_port;
        if ($port = "") {
            rewrite ^/stable-(.*)/static/(.*) /port/$1/stable-$2/static/$3 last;
        }

        proxy_pass http://127.0.0.1:$port/stable-$1/static/$2;
    }

    location ~ /stable-(.*)/vscode-remote-resource {
        set $port $cookie_port;
        if ($port = "") {
            rewrite ^/stable-(.*)/vscode-remote-resource /port/$1/stable-$2/vscode-remote-resource last;
        }

        proxy_pass http://127.0.0.1:$port/stable-$1/vscode-remote-resource;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location ~ /stable-(.*) {
        set $port $cookie_port;
        if ($port = "") {
            rewrite ^/stable-(.*) /port/$1/stable-$2 last;
        }

        proxy_pass http://127.0.0.1:$port/stable-$1;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
    }

    location ~ /port/(\d+)/ {
        set $port $cookie_port;
        if ($port = "") {
            set $port $1;
            add_header Set-Cookie "port=$port; Path=/";
        }

        proxy_pass http://127.0.0.1:$port/;

        sub_filter_types text/html;

        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Host $server_name;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass_request_headers on;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
    }
}

is useful to us