coder / code-server

VS Code in the browser
https://coder.com
MIT License
67.27k stars 5.51k forks source link

[Bug]: Error: WebSocket close with status code 1006 #6644

Closed octopus2181 closed 6 months ago

octopus2181 commented 6 months ago

Is there an existing issue for this?

OS/Web Information

Steps to Reproduce

  1. If I set the port to 443:443 in the docker compose of linuxserver/swag ,reverse proxies are good. I was able to use code-server in the docker .
  2. But If I set a different port mapping 443 in the docker compose of linuxserver/swag (such as 9091:443), I can't use code-server .

Expected

Because my port 443 remote access is forbidden, I want to works with a different port (such as 9091 ).

Actual

"The workbench failed to connect to the server (Error: WebSocket close with status code 1006)"

Logs

##code-server.yml
version: "3"
services:
    code-server:
        container_name: code-server
        image: codercom/code-server
        external_links:
          - swag-network
        ports:
          - 8080:8080
        volumes:
          - /d/Docker_hub/code_server/config:/config
        environment:
          - PUID=1000
          - PGID=1000
          - TZ=Asia/Shanghai
          - PASSWORD=*******
          - PROXY_DOMAIN=code-server.example.dynv6.net #optional
          - DEFAULT_WORKSPACE=/config/workspace
        restart: always

##swag.yml
version: "3"
services:
  swag:
    container_name: swag
    image: linuxserver/swag
    cap_add:
      - NET_ADMIN
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Asia/Shanghai
      - URL=example.dynv6.net
      - SUBDOMAINS=wildcard
      - VALIDATION=dns
      - DNSPLUGIN=rfc2136
    volumes:
      - /d/Docker_hub/swag_9091/config:/config
    ports:
      - 9091:443
      - 8081:80 #optional
    restart: unless-stopped
networks:
  swag-network:
    driver: bridge

##/config/nginx/proxy-confs/code-server.subdomain.conf
server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name code-server.* "~^[0-9]{1,10}\.linux-code-server\..*$";
    include /config/nginx/ssl.conf;
    client_max_body_size 0;
    location / {
        include /config/nginx/proxy.conf;
        include /config/nginx/resolver.conf;
        set $upstream_app code-server;
        set $upstream_port 8080;
        set $upstream_proto http;
        proxy_pass $upstream_proto://$upstream_app:$upstream_port;
    }
}

Screenshot/Video

No response

Does this issue happen in VS Code or GitHub Codespaces?

Are you accessing code-server over a secure context?

Notes

No response

code-asher commented 6 months ago

Thank you for the reproduction details! I had trouble using them because it seems Swag is trying to generate real certificates and it does not look like they have an option to generate self-signed certificates?

Could you run code-server again with the LOG_LEVEL=debug environment variable and tell me if you see any messages like "blocking request"?

code-asher commented 6 months ago

Looks like /config/nginx/proxy.conf contains these lines:

proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;

I think you already tried setting Host, right? code-server will prefer X-Forwarded-Host over Host so it might work to override it:

proxy_set_header X-Forwarded-Host $http_host;

We really need to fix https://github.com/coder/code-server/issues/6166

octopus2181 commented 6 months ago

Oh , yes ! I am setting proxy_set_header X-Forwarded-Host $http_host ,it woks . The port 9091 can connect to the code-server . Thank you !