The workbench failed to connect to the server (Error: WebSocket close with status code 1006)
OS/Web Information
- Web Browser: Chromium (brave), although I also tested with Firefox and Edge and got the same result.
- Local OS: Windows 11
- Remote OS: Ubuntu
- Remote Architecture: x86-64
code-server --version: 3.12.0
Steps to Reproduce
- Ran code-server (i also tried using --proxy-domain
to see if I got any different results.) I used nginx to reverse proxy to my domain, I also use Cloudflare. - When I open the domain on my browser, I get
The workbench failed to connect to the server (Error: WebSocket close with status code 1006)
Expected
The server would work normally.
Actual
See error above.
Logs
Logs look normal for the remote server, however browser gives error:
[vscode] failed to initialize VS Code vscode.browserified.js:726:13
[4]< <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:726
o <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:1
r <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:1
<anonymous> <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:1
(I replaced my domain with
Error: [vscode] Could not set body background to theme background color. Could not find colorThemeData in localStorage.
setBodyBackgroundToThemeBackgroundColor <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:668
main <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:719
[4]< <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:723
o <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:1
r <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:1
<anonymous> <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:1
vscode.browserified.js:727:13
[4]< <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:727
o <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:1
r <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:1
<anonymous> <domain>/static/b37ff28a0a582aee84a8f961755d0cb40a4081db/usr/lib/code-server/out/browser/pages/vscode.browserified.js:1
Screenshot

Notes
This issue can be reproduced in VS Code: No
--host 0.0.0.0 --trusted-origins=*
@wangyizhi1 Awesome, this works!
For those that may be needing to proxy through IIS, here is a couple rewrite rules for that. This app uses permessage-deflate which ARR does not support, so the request fails with this 1006 error message
<rule name="removepermessagedeflate">
<match url=".*" />
<conditions>
<add input="{HTTP_SEC_WEBSOCKET_EXTENSIONS}" pattern="permessage-deflate(.*)" />
</conditions>
<serverVariables>
<set name="HTTP_SEC_WEBSOCKET_EXTENSIONS" value="{C:1}" />
</serverVariables>
<action type="None" />
</rule>
<rule name="proxy">
<match url=".*" />
<action type="Rewrite" url="http://10.8.0.4:8080/{R:0}" />
</rule>
where is the nginx.conf file?
console into the nginx container
docker ps | grep nginx
docker exec -it <container_name or ID> /bin/sh
# console in container
cat /etc/nginx/nginx.conf
for me, below is work: (docker run & nginx proxy outside the docker container)对我来说,下面是工作:(docker在docker容器外运行nginx代理)
location / { add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Methods *; add_header Access-Control-Allow-Headers *; # proxy_ssl_verify off; proxy_set_header Host $host; proxy_set_header Accept-Encoding gzip; #proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Host $host:$server_port; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $http_connection; proxy_http_version 1.1; proxy_pass http://127.0.0.1:8081/; }This configuration works for me.这个配置对我来说很有用。
This works for me. I've tried lots of configuration, the key line is
proxy_set_header X-Forwarded-Host $host:$server_port;这对我很有效。我尝试过很多配置,关键行是proxy_set_header X-Forwarded-Host $host:$server_port;
Worked like a charm. Indeed the key line is proxy_set_header X-Forwarded-Host $host:$server_port;
for me, below is work: (docker run & nginx proxy outside the docker container)
location / { add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Methods *; add_header Access-Control-Allow-Headers *; # proxy_ssl_verify off; proxy_set_header Host $host; proxy_set_header Accept-Encoding gzip; #proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Host $host:$server_port; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $http_connection; proxy_http_version 1.1; proxy_pass http://127.0.0.1:8081/; }This configuration works for me.
This works for me. I've tried lots of configuration, the key line is
proxy_set_header X-Forwarded-Host $host:$server_port;
This is particularly important for those who access other programs on the server through the proxy + nginx, and these programs only listen on the port of 127.0.0.1.