解决反代code-server出现websocket连接错误

142 字
1 分钟
解决反代code-server出现websocket连接错误

使用 nginx 反代 code-server 时,使用默认配置,会出现以下错误:

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

1.png
1.png

找到 1panel 的网站 - 网站设置 - 反向代理 - 源文 中,

屏幕截图_21-8-2024_1733.jpeg
屏幕截图_21-8-2024_1733.jpeg

替换为以下内容:

location ^~ / {
proxy_pass http://127.0.0.1:40035;
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;
}

这样就能使得 Websocket 协议顺利通过反向代理。然后就能顺利访问、不会有任何问题了:

屏幕截图 2024-08-21 170013.png
屏幕截图 2024-08-21 170013.png

支持与分享

如果这篇文章对你有帮助,欢迎分享给更多人或赞助支持!

赞助
解决反代code-server出现websocket连接错误
https://www.0x3f.foo/posts/codeserver/
作者
Dignite
发布于
2024-08-21
许可协议
CC BY-NC-SA 4.0

评论区

Profile Image of the Author
Dignite
When nothing goes right, go left.
公告
欢迎来到我的博客!这是一则示例公告。
分类
标签
站点统计
文章
146
分类
5
标签
271
总字数
314,753
运行时长
0
最后活动
0 天前

目录