Docker – Apache ProxyPass Docker Containers Returning 503

apache-2.4dockerreverse-proxyvirtualhost

I am stuck getting started with containerized virtualhosts. The set up is as follows:

mydomain.com

  • Ubuntu VPS (digitalOcean, for context), Docker pre installed
    • Apache container (reverse proxy), guest port 80 to host 80
    • Web-app container (running apache), guest port 80 to host 8081

Apache is serving fine, apache info page shows at mydomain.com and web-app shows at mydomain.com:8081

The issue is trying to ProxyPass sub.mydomain.com to serve mydomain.com:8081

I have devised the following sites-available/sub.mydomain.com.conf in the Apache container.

<VirtualHost *:80>
ServerName sub.mydomain.com
ProxyPreserveHost on
ProxyRequests off
<Proxy *>
    Order deny,allow
    Allow from all
</Proxy>
ProxyPass           "/" "http://localhost:8081/" retry=0
ProxyPassReverse    "/" "http://localhost:8081/"

However, sub.mydomain.com returns a 503 error.

I have also added the following DNS records with digitalOcean:
– CNAME: *.mydomain.com is an alias of mydomain.com
– A: sub.mydomain.com directs to [DROPLET IP]

I have also tried:
replacing 'localhost' in :

ProxyPass           "/" "http://localhost:8081/" retry=0
ProxyPassReverse    "/" "http://localhost:8081/"

with mydomain.com and DROPLET IP and the [gateway] ip returned by route executed from inside the Apache container. Changing to these values either gives the same 503 error, or results in the page continuously loading, returning neither an error nor the page requested. I am at a loss for what to try next, any help is appreciated. There are so many disparate settings that I think a more experienced individual might be able to point out where I have gone wrong. Thanks in advance!

Best Answer

In the proxy container you can't use localhost:8081 as the proxy address. localhost is in fact the loopback address of the container itself, not your host server and there is nothing listening on port 8081 there (causing the 503).

My suggestion is to use docker only for you service and use a standard apache (or even better nginx) for proxying.