1An unexpected error occurred that requires a reload of this page.
2The workbench failed to connect to the server (Error: WebSocket close with status code 1006)
Code server popped up a websocket error when I exposed code-server using a custom domain and a custom port via nginx.
Here is part of my nginx.conf.
1 upstream code{
2 server xxxxxxxxx;
3 }
4 server {
5 listen 40032 ssl;
6 server_name xxxxxxxx;
7 ssl_certificate certs/mycert.pem;
8 ssl_certificate_key certs/mykey.pem;
9 ssl_ciphers HIGH:!aNULL:!MD5;
10 charset utf-8;
11 client_max_body_size 500M;
12 location / {
13 proxy_pass http://code;
14 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
15 proxy_set_header Host $host;
16 proxy_set_header Upgrade $http_upgrade;
17 proxy_set_header Connection "upgrade";
18 proxy_http_version 1.1;
19 proxy_set_header Accept-Encoding gzip;
20 }
21 }
Websocket support has already been enabled by adding proxy_http_version 1.1
and proxy_set_header Upgrade $http_upgrade
,
but this error is still being reported.
The key to the problem lies in the proxy_set_header Host $host;
in the above configuration, after changing it to
proxy_set_header Host $http_host;
, problem disappeared.
Here is the explanation:
Based on Nginx 1.18, code-server: v4.17.1