code-server icon indicating copy to clipboard operation
code-server copied to clipboard

Web socket fails to connect through Apache

Open lplassman opened this issue 4 years ago • 52 comments

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

139257954-98741db0-07d2-47f0-a529-fbe57cdd1188 Screen Shot 2022-01-10 at 10 47 35 PM Screen Shot 2022-01-10 at 10 48 36 PM

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

lplassman avatar Jan 11 '22 04:01 lplassman

I am having the same issue with code-server 4.2.0 and Server version: Apache/2.4.18 (Ubuntu)

khanakia avatar Mar 29 '22 06:03 khanakia

Yes, same here. Was hoping 4.2.0 would fix the issue but alas.

Is there no workaround at all? My Code Server in Home Assistant has been unusable for many weeks now :(

piit79 avatar Mar 29 '22 06:03 piit79

Is there no workaround at all?

Use http://youre_local_ip_server:8123/ When used from a local network address - Code Server is work.

SCratORS avatar Mar 29 '22 06:03 SCratORS

Well, since this issue is Apache-specific, not using Apache obviously "works around" the issue, but that's not a really usable answer.

KaKi87 avatar Mar 29 '22 09:03 KaKi87

Well, since this issue is Apache-specific, not using Apache obviously "works around" the issue, but that's not a really usable answer.

Especially as most, if not all, are using Apache as a reverse proxy. Assuming this is configured, like myself, for remote access jumping through a single web host externally…

😅

jamieshaw avatar Apr 03 '22 05:04 jamieshaw

This was the push I needed to migrate my reverse proxy server from Apache to NGINX, which had been on my long term to do list for years.

I set up NGINX Proxy Manager via Docker Compose, and recreating my proxy hosts was much less painful than I had feared. NGINX reverse proxy works flawlessly with my code server instance (4.X), which is installed as a Home Assistant add-on.

Of course this won't be an option for everyone, but if migrating is feasible for you, I would recommend looking into it.

krazos avatar Apr 03 '22 10:04 krazos

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.

KaKi87 avatar Apr 03 '22 11:04 KaKi87

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.47 may work.

I was experiencing websocket 1006 errors on Apache/2.4.41

Apache's mod_proxy_wstunnel documentation mention this:

Since httpd 2.4.47, mod_proxy_http can handle WebSocket upgrading and tunneling in accordance to RFC 7230, this directive controls whether mod_proxy_wstunnel should hand over to mod_proxy_http to this, which is the case by default.

Setting to Off lets mod_proxy_wstunnel handle WebSocket requests as in httpd 2.4.46 and earlier.

The grammar is a bit off, but I just assumed Apache was handling the websocket proxy incorrectly and I updated apache.

Hope this helps!

leuit avatar Apr 21 '22 14:04 leuit

Thanks @leuit, upgrading to Apache/2.4.53 solved the issue

gmiscione avatar Apr 21 '22 15:04 gmiscione

Thank you @leuit. Upgrading apache2 to 2.4.53 solved the issue for me as well.

lplassman avatar Apr 21 '22 15:04 lplassman

Closing this since the issue seems fixed

lplassman avatar Apr 21 '22 15:04 lplassman

@leuit Thanks!

SCratORS avatar Apr 21 '22 15:04 SCratORS

I am running apache2 v2.4.38, and can't seem to be able to get a newer version. apt policy apache2 outouts the following :

apache2:
  Installed: 2.4.38-3+deb10u7
  Candidate: 2.4.38-3+deb10u7

KaKi87 avatar Apr 21 '22 15:04 KaKi87

@KaKi87 I had to add this repository, and then reinstall apache to upgrade beyond 2.4.41

sudo add-apt-repository ppa:ondrej/apache2 

lplassman avatar Apr 21 '22 15:04 lplassman

I am running Debian (10), not Ubuntu.

KaKi87 avatar Apr 21 '22 15:04 KaKi87

@KaKi87

I am running Debian (10), not Ubuntu.

Try using this to add the repository: curl -sSL https://packages.sury.org/apache2/README.txt | sudo bash -x

Then proceed with upgrading apache2.

Disclaimer: I'm not familiar with Debian. I'm suggesting this based on this guide

leuit avatar Apr 21 '22 15:04 leuit

I successfully upgraded both apache2 and code-server, thanks !

KaKi87 avatar Apr 21 '22 16:04 KaKi87

I am using Apache2 version 2.4.53 and cannot use the workaround from @leuit , as disabling mod_proxy_http breaks other services I run on my server. Is there another fix?

ihowell avatar May 05 '22 18:05 ihowell

You don't need to disable that. Once upgraded, it just works.

KaKi87 avatar May 05 '22 19:05 KaKi87

@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:

<VirtualHost *:80>
	     ServerName vscode.mydomain.com
	     UseCanonicalName on
	     Redirect / https://vscode.mydomain.com
</VirtualHost>

<VirtualHost *:443>
	     ServerName vscode.mydomain.com
	     
	     # setup the proxy
	     ProxyRequests off
	     <Proxy *>
	     	    Order deny,allow
		    Allow from all
	     </Proxy>

	     ProxyErrorOverride On

	     Header set Connection "Upgrade"
	     RequestHeader setifempty Connection "Upgrade"
	     Header set Upgrade "websocket"
	     RequestHeader setifempty Upgrade "websocket"

	     ProxyPass / http://192.168.50.60:8081/
	     ProxyPassReverse / http://192.168.50.60:8081/

	     <Location />
	     	       Order allow,deny
		       Allow from all
	     </Location>

	     SSLEngine on
	     Include /etc/letsencrypt/options-ssl-apache.conf
	     ErrorLog "/var/log/apache2/error.vscode.mydomain.dev.log"
	     SSLCertificateFile /etc/letsencrypt/live/mydomain/fullchain.pem
     	     SSLCertificateKeyFile /etc/letsencrypt/live/mydomain/privkey.pem
</VirtualHost>

And on the other machine I'm using code-server --bind-addr 0.0.0.0:8081 to start it. Any ideas?

ihowell avatar May 05 '22 19:05 ihowell