Repository navigation
Web socket fails to connect through Apache #4723
Description
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 735c6da
[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]
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



Activity
JimmyNi commentedon Jan 12, 2022
Same issue here. Using apache2 with reverse proxy. Only occur with 4.0.1, code-server 3.12.0 works fine for me.
jsjoeio commentedon Jan 13, 2022
@code-asher any ideas?
code-asher commentedon Jan 13, 2022
konni commentedon Jan 17, 2022
Same issue here using apache2 with reverse proxy
jamieshaw commentedon Jan 17, 2022
Ditto.
3.12.0 works fine. 4.0.1 returns 1006.
apache2 reverse proxy.
sobakaio commentedon Jan 19, 2022
Same issue.
gmiscione commentedon Jan 19, 2022
Same issue, 3.12.0 works fine and 4.0.1 fails with this error. I'm using apache2 as a reverse proxy. Trying to access the service directly without the proxy seems to work
code-asher commentedon Jan 19, 2022
Sounds like we need to spin up Apache and try to reproduce.
dokastho commentedon Jan 19, 2022
I found a fix on nginx #4763 not sure if there’s an Apache analog for those settings
siklosi commentedon Jan 24, 2022
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.
KaKi87 commentedon Jan 24, 2022
Me neither.
I cannot find any documentation on said flag, how does it work ?
Would there be a
--disableflag too, which would allow apache users to upgrade to 4.x ?code-asher commentedon Jan 26, 2022
code-asher commentedon Jan 26, 2022
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)31 remaining items
ihowell commentedon May 5, 2022
I am using Apache2 version 2.4.53 and cannot use the workaround from @leuit , as disabling
mod_proxy_httpbreaks other services I run on my server. Is there another fix?KaKi87 commentedon May 5, 2022
You don't need to disable that. Once upgraded, it just works.
ihowell commentedon May 5, 2022
@KaKi87 Well, it isn't working for me, and neither is v3.12. I am however, running code-server on a separate machine than the apache server and just trying to forward the site. This is the current config I'm using:
And on the other machine I'm using
code-server --bind-addr 0.0.0.0:8081to start it. Any ideas?leuit commentedon May 5, 2022
@ihowell
Are you receiving the same error as OP? Is it not upgrading the websocket connection properly?
You say you're running code-server on a separate machine from apache; can you directly access code-server via the port it's listening on? Depending on the error you're receiving, I think it may just be a communication issue.
If you are indeed receiving the error on the websocket upgrade and can access the frontend webpage of code-server; you'll simply just need to upgrade apache2 as the version does not handle websocket upgrades according to RFC 7230
ihowell commentedon May 5, 2022
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.
leuit commentedon May 6, 2022
@ihowell Wonderful! I was going to suggest changing the apache config next; glad you got it resolved!
KaKi87 commentedon May 6, 2022
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. :)
Drealine commentedon May 21, 2022
Upgrade Apache2 to 2.4.52 also solved the issue for me without change anythingelse in apache configuration.
maverjk commentedon May 30, 2022
Hi @ihowell can you please share your solution? I have your same issue running last Apache version (2.4.6)
lachlansimpson commentedon Sep 16, 2022
Upgrading apache2 worked for me.
qjaden commentedon Sep 3, 2023
This issue has not been resolved in version 4.
mashroomxl commentedon Nov 12, 2023
try nginx config as follows:
config above working for me. my scene:
lilithebowman commentedon Apr 24, 2025
As of Apache
2.4.58I'm still having this issue. 😒KaKi87 commentedon Apr 24, 2025
Share your config.
lilithebowman commentedon Apr 24, 2025
Sure thing! Sorry I was just cleaning up my
/etc/apache2/sites-available/because it's been there for years with a few unnecessary site configs and things LetsEncrypt made that don't need to be there. Now that it's cleanly whittled down to the configs I need for my sites, I can begin to debug this.Okay false alarm. Here is my fixed config!
cat /etc/apache2/sites-available/code-server.conf