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
i got this too. i ran it in docker. i found there must be lines below in the nginx.conf to make it work location / { proxy_pass http://codeserver.xxx.xxx:8443/; proxy_set_header Host $host; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection upgrade; proxy_set_header Accept-Encoding gzip; } this is from https://github.com/cdr/code-server/blob/main/docs/guide.md#using-lets-encrypt-with-nginx
proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection upgrade; proxy_set_header Accept-Encoding gzip;
Thanks, that seemed to work.
Any idea which version broke this? I can't get it to work with Nginx-Proxy-Manager so I'll just downgrade until code-server gets it's sh*t together.
cc @code-asher
Those headers enable proxying websockets so it is not a code-server issue as far as I can tell.
If anyone is looking for a solution for ingress-nginx on Kubernetes like I was, add this annotation to your ingress
nginx.org/websocket-services: "code-server"
Replace code-server with whatever your code-server service name is.
A little late now, but does anyone have a working configuration for Apache2?
A little late now, but does anyone have a working configuration for Apache2?
Hey looking for the same thing, having issues proxying code server in apache2
When adding the domain or subdomain for code-server on Nginx Proxy Manager make sure to check the Websockets support to solve the problem.

@tinuh @ZandercraftGames For those having issues with reverse proxy in Apache, refer to https://github.com/coder/code-server/issues/4723#issuecomment-1105319574
I hope this works for you!
A little late now, but does anyone have a working configuration for caddy2?
proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection upgrade; proxy_set_header Accept-Encoding gzip;
Thank you very much. It's very useful to me.
for kubernetes, I had to add BOTH suggestions from Link1 and annotations as follows.
PS: the {{ .Values.user }} etc, are dynamic values from values.yml of helm chart which you need to replace
nginx.org/websocket-services: code-server-{{ .Values.user }}
nginx.org/server-snippets: |
location / {
proxy_pass http://{{ .Values.host_domain }}:{{ .Values.port }}/;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
proxy_set_header Accept-Encoding gzip;
}
Entire example below using helm chart
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: code-server-{{ .Values.user }}
namespace: {{ .Values.namespace }}
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.org/websocket-services: code-server-{{ .Values.user }}
nginx.org/server-snippets: |
location / {
proxy_pass http://{{ .Values.host_domain }}:{{ .Values.port }}/;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
proxy_set_header Accept-Encoding gzip;
}
spec:
tls:
- hosts:
- {{ .Values.host_domain }}
secretName: code-server-secret-{{ .Values.user }}
rules:
- host: {{ .Values.host_domain }}
http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: code-server-{{ .Values.user }}
port:
number: {{ .Values.port }}
Hello, leaving this comment here just in case anyone in the future is having this issue.
Cloudflare tunnels, got this same error. Solution was going to dash.cloudflare.com and setting websockets to enabled

When adding the domain or subdomain for code-server on Nginx Proxy Manager make sure to check the Websockets support to solve the problem.
This worked Thank you. I was having trouble with error on OpenBooks and this fixed that to.
A little late now, but does anyone have a working configuration for caddy2?
Did you ever get a resolution to this?
If you are facing wss:// websocket 1006 error on kubernetes with NGINX Ingress Controller, you can try to add timeout annotations to service ingress.
nginx.org/proxy-read-timeout: "3600"
nginx.org/proxy-send-timeout: "3600"
I don't want to wake up an old issue. But I've had it working, and suddenly this error came. I'm using swag and my reverse proxy conf was working fine. The suggested addition of headers didn't work. Any tips?
Just to confirm, is Host one of the headers you added? v4.10.0 added a security check that uses the host and origin headers.
@code-asher thanks. Adding Host solved the issues with v4.12.0.