code-server: Web socket fails to connect through Apache
OS/Web Information
- Web Browser: Chrome
- Local OS: MacOS 12.2
- Remote OS: Ubuntu 20.04 LTS
- Remote Architecture: amd64
code-server --version: 4.0.1
Logs
code-server --log debug [2022-01-11T03:38:43.612Z] info code-server 4.0.1 735c6da829535969ff7193c79379299e4a1cb9bc [2022-01-11T03:38:43.613Z] info Using user-data-dir ~/.local/share/code-server [2022-01-11T03:38:43.628Z] info Using config file ~/.config/code-server/config.yaml [2022-01-11T03:38:43.628Z] info HTTP server listening on http://0.0.0.0:8080/ [2022-01-11T03:38:43.628Z] info - Authentication is enabled [2022-01-11T03:38:43.628Z] info - Using password from ~/.config/code-server/config.yaml [2022-01-11T03:38:43.628Z] info - Not serving HTTPS [22:38:51] Extension host agent started. [22:38:51] [Theme Service] Scanning for theme extension… [22:38:51] [Theme Service] theme-abyss [22:38:51] [Theme Service] theme-defaults [22:38:51] [Theme Service] theme-kimbie-dark [22:38:51] [Theme Service] theme-monokai [22:38:51] [Theme Service] theme-monokai-dimmed [22:38:51] [Theme Service] theme-quietlight [22:38:51] [Theme Service] theme-red [22:38:51] [Theme Service] theme-solarized-dark [22:38:51] [Theme Service] theme-solarized-light [22:38:51] [Theme Service] theme-tomorrow-night-blue [22:38:51] [Theme Service] Attempting to find user’s active theme: Default Dark+ [2022-01-11T03:38:54.949Z] debug got latest version {“latest”:“4.0.1”} [2022-01-11T03:38:54.949Z] debug comparing versions {“current”:“4.0.1”,“latest”:“4.0.1”} [2022-01-11T03:39:51.007Z] debug 0 active connections
Screenshot

Notes
I currently only experience this error on code-server 4.0.1. code-server 3.12.0 works without issue. I am currently using apache2 with a reverse proxy. The current config for the apache2 virtual host is below:
<Location “/”> ProxyPass http://127.0.0.1:8080/ ProxyPassReverse http://127.0.0.1:8080/ ProxyPassReverse / RewriteEngine on RewriteCond %{HTTP:Upgrade} websocket [NC] RewriteCond %{HTTP:Connection} upgrade [NC] RewriteRule ^/?(.*) “ws://127.0.0.1:8080/” [P,L] </Location>
I also made sure all the websockets modules are loaded in apache2 and working without problems. No errors occur on the Apache web server. Any suggestions on how to get this working with Apache2?
This issue can be reproduced in VS Code: No
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 46
- Comments: 49 (6 by maintainers)
For those affected, what version of Apache are you running?
I was able to resolve the issue by updating apache2 to
Apache/2.4.53— however, I believe any version>= Apache/2.4.47may work.I was experiencing websocket 1006 errors on
Apache/2.4.41Apache’s mod_proxy_wstunnel documentation mention this:
The grammar is a bit off, but I just assumed Apache was handling the websocket proxy incorrectly and I updated apache.
Hope this helps!
Confirming I was able to reproduce:
localhostin browserThen to confirm it is a 4.0.1 issue I killed code-server with
C-cand installed 3.12.0 with yarn:localhostin browser (Apache is still running from earlier)I have 35 enabled apache configurations and am not going to migrate to nginx for this.
However, I am stuck to version 3.x until this bug is solved.
Here’s my working config using
apache2v2.4.52 &code-serverv4.3.0, usingProxyPass(andRewriteEngineonly for WebSocket).I always try to make those as light as possible. I don’t think proxying to the local host or to another host on the local network changes anything. Also, @ihowell, when making future reports about something that isn’t working, please document the unexpected behavior as much as you can, because it is as important as documenting your configuration. 😃
Sounds like we need to spin up Apache and try to reproduce.
I successfully upgraded both
apache2andcode-server, thanks !Well, since this issue is Apache-specific, not using Apache obviously “works around” the issue, but that’s not a really usable answer.
I’m guessing that line from release log “Web socket compression has been made the default (when supported). This means the --enable flag will no longer take permessage-deflate as an option” is causing problem. I tried finding analog to “proxy_set_header Accept-Encoding gzip” nginx but I have not yet figured way to make it work.
FYI: I also see some content security policy complaints in console log. There are also some 1006 errors, that are resolved in newer versions https://github.com/microsoft/vscode-remote-release/issues/6031 Although code server works without apache reverse proxy (http, not https), that’s not really clever to run though the internet 😃
Ditto.
3.12.0 works fine. 4.0.1 returns 1006. apache2 reverse proxy.
Same issue here using apache2 with reverse proxy
I am receiving the same 1006 error as op, however I don’t know how to tell if the websocket is being upgraded properly. I can access code-server from http://192.168.50.60:8081 in my browser and everything works fine. I just followed instructions and upgraded my server to Apache2 version 2.4.53, but it still isn’t working.
Edit: When I run code-server with
--log debug, I don’t see any errors in the logs.Edit 2: I now have it working by using the rewriting rules above instead of using my configuration for proxy passing and reverse proxy passing.
@KaKi87
Try using this to add the repository:
curl -sSL https://packages.sury.org/apache2/README.txt | sudo bash -xThen proceed with upgrading apache2.
Disclaimer: I’m not familiar with Debian. I’m suggesting this based on this guide
@KaKi87 I had to add this repository, and then reinstall apache to upgrade beyond 2.4.41
@leuit Thanks!
Thank you @leuit. Upgrading apache2 to 2.4.53 solved the issue for me as well.
Thanks @leuit, upgrading to Apache/2.4.53 solved the issue
I’m hosting
code-serverin a dedicated server so I’m definitely in a different network.Update! The problem was resolved when I tried it from an outside network. So it may have something to do with local routing / proxying differences. Unsure if this is directly related, but my websocket 1006 has been resolved. If I’m local and want to test through the domain I have it on, I’ll have to figure out something else.
Websocket 1006 error occurred under these conditions.
I’m also seeing this bug, with NGINX (using nginx proxy manager). I’m currently trying to fix with https://github.com/coder/code-server/issues/4763 but I’m not having any luck. Latest docker version of code-server.
If the exact same config works with 3.12 that does seem like it could be an issue with 4.0 but I have no idea how; so far all the 1006 errors I have seen have been caused by misconfiguration.
I am not very familiar with Apache but maybe this comment has a clue:
https://github.com/coder/code-server/discussions/2104#discussioncomment-360665