question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

code-server behind apache proxy

See original GitHub issue

Description

I can’t figure out the correct apache config in order to proxy https and wss requests correctly. My apache config looks something like this:

<VirtualHost *:443>
    ServerName code.mydomain.net

    ProxyRequests off
    ProxyPreserveHost on
    AllowEncodedSlashes NoDecode

    RequestHeader set X-Forwarded-Proto https
    RequestHeader set X-Forwarded-Port 443

    ProxyPass / http://code.code:8080/ nocanon
    ProxyPassReverse / http://code.code:8080/

    Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>

My problem is now, that this configuration blocks all websocket requests. In order to also proxy websocket connections I would need to add something like this to my apache config:

    ProxyPass / ws://code.code:8080/
    ProxyPassReverse / http://code.code:8080/

The problem with this is, that this will not work with the same url path like the https proxy statements (https://code.mydomain.net/ and wss://code.mydomain.net/). Usually the websocket connection would be handled by a different path (eg.: wss://code.mydomain.net/websocket/). So my question is: Is there any way to achieve this with code-server and apache?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
Foxturcommented, Mar 19, 2019

I’ve those rules after the ServerName definition and it seem’s to do the job.

RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /(.*)           ws://127.0.0.1:3000/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /(.*)           http://127.0.0.1:3000/$1 [P,L]
4reactions
waclaw66commented, Sep 11, 2019

I’ve those rules after the ServerName definition and it seem’s to do the job.

RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /(.*)           ws://127.0.0.1:3000/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /(.*)           http://127.0.0.1:3000/$1 [P,L]

This stopped working for V2, do you know how to fix it? Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to run code-server behind Cloudflare and Apache (same ...
Hi! Currently I have a VPS proxied by Cloudflare, with a reverse-proxy under Apache to run my various servers.
Read more >
how to convert nginx config file from code-server to apache2 ...
So finally I found the solution to my problem, I had to use apache reverse proxy. I didn't understand all the code but...
Read more >
Usage - code-server v4.8.0 docs - Coder
If you're working on web services and want to access them locally, code-server can proxy to any port using either a subdomain or...
Read more >
Run code-server with Apache - chrislynch.link
Caddy can create a reverse proxy to code-server, letting you access it over SSL on port 443 easily even though it is really...
Read more >
mod_proxy - Apache HTTP Server Version 2.4
Apache HTTP Server can be configured in both a forward and reverse proxy (also known as gateway ) mode. An ordinary forward proxy...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found