Score:0

How to setup Apache as reverse proxy to a docker container

jp flag

I struggling to setup my Apache server as reverse proxy for a docker contained Greenlight instance.

In the official docs it is proposed to run Greenlight in a docker container with an Nginx instance as revers proxy (mainly to make it easy to run it alongside a BBB server). In my setup however I do not want to run my own BBB instance but rather use Greenlight as a frontend for an external BBB server.

But for convenience I set up Greenlight in a docker container nevertheless.

But as my server has many purposes (mainly it's used to deliver several websites and provide e-mail accounts both manged by Froxlor but it works also as an Matrix server) I do not want to setup Nginx as proxy, for that would force me to substantially change my actual running Froxlor manged Apache setup.

So I was trying to configure Apache instead as an revers prox. Unfortunately in the docs is only a Nginx example:

location /b {
  proxy_pass          http://127.0.0.1:5000;
  proxy_set_header    Host              $host;
  proxy_set_header    X-Forwarded-For   $proxy_add_x_forwarded_for;
  proxy_set_header    X-Forwarded-Proto $scheme;
  proxy_http_version  1.1;
}

location /b/cable {
  proxy_pass          http://127.0.0.1:5000;
  proxy_set_header    Host              $host;
  proxy_set_header    X-Forwarded-For   $proxy_add_x_forwarded_for;
  proxy_set_header    X-Forwarded-Proto $scheme;
  proxy_set_header    Upgrade           $http_upgrade;
  proxy_set_header    Connection        "Upgrade";
  proxy_http_version  1.1;
  proxy_read_timeout  6h;
  proxy_send_timeout  6h;
  client_body_timeout 6h;
  send_timeout        6h;
}

I tied to make this work on Apache with the following VirtualHost settings:

<VirtualHost MYIP:443>
  ServerName greenlight.example.com
ProxyPreserveHost On
ProxyRequests Off
ProxyVia On
ProxyPass / http://127.0.0.1:5000
ProxyPassReverse / http://127.0.0.1:5000   
<Location "/cable">
  ProxyPass / http://127.0.0.1:5000 connectiontimeout=6h timeout=6h
  ProxyPassReverse / http://127.0.0.1:5000
</Location>
</VirtualHost>

I divert from the example that I do not want to use a virtual subfolder »b« but rather a subdomain t redirect specific traffic to the local port 5000. Unfortunately this isn't working. The server returns

502 Prox error

Proxy Error

The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request

Reason: Error reading from remote server

Can somebody please explain to me what could be the reason for this error? How to translate the Nginx Header settings to Apache and the other timeout settings and are they even necessary?

drookie avatar
za flag
So basically you are trying to do the opposite of what the industry currenly does. Hilarious.
jp flag
@drookie You mean switching for Nginx to Apache? Well, no, I' am not. I just want to install Greenlight on a server that happens to run many other things with Apache and it does not make any sense to reconfigure dozen applications because the ›industries‹ thinks Nginx is cooler.
djdomi avatar
za flag
no you didnt got the point. you should use nginx as a cache and run the apps on apache. thats thw point he wanted to tell. So tell the original issue because imho you have a [x and y issue](https://faq-database.de/doku.php?id=en:x-and-y-problem)
jp flag
@djdomi Thanks for the comment. Maybe you are right. I changed the question trying to give more background. I did not want to be too specific at first…
Score:2
in flag

There are a few issues here:

  1. Order
    The first matched path wins. You placed / before /cable, so / will match always and /cable will never be used.
  2. matching trailing slashes
    If you end the first parameter of ProxyPass with a / you need to add one to the second, and vice versa. Otherwise you'll end up with non working URLs sent to the backend
  3. ProxyPass inside a <Location> block
    If you use ProxyPass inside a <Location> it only gets the second parameter. The first is being replaces by the <Location>.

Example:

<VirtualHost MYIP:443>
    ServerName greenlight.example.com
    ProxyPreserveHost On
    ProxyRequests Off
    ProxyVia On
    ProxyPass /cable http://127.0.0.1:5000 connectiontimeout=6h timeout=6h
    ProxyPassReverse /cable http://127.0.0.1:5000
    ProxyPass / http://127.0.0.1:5000/
    ProxyPassReverse / http://127.0.0.1:5000/
</VirtualHost>

Last, but not least, currently you are proxying both locations to the same backend URL. This is usually wrong.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.