# Dockers as virtual host in Apache

**URL:** <https://community.learnlinux.tv/t/dockers-as-virtual-host-in-apache/314>\
**Category:** Homelab\
**Created:** [March 17, 2021, 11:00am UTC](https://community.learnlinux.tv/t/dockers-as-virtual-host-in-apache/314 "2021-03-17T11:00:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![CptCharis](https://community.learnlinux.tv/letter_avatar_proxy/v4/letter/c/7993a0/32.png) [@CptCharis](https://community.learnlinux.tv/u/CptCharis)\
**Post date:** [March 17, 2021, 11:00am UTC](https://community.learnlinux.tv/t/dockers-as-virtual-host-in-apache/314/1 "2021-03-17T11:00:40Z")

</div>

Hello every body. Hope all of you are healthy.

Playing around with Docker containers and web servers, I am facing a “challenge”.

I run Apache as web server in CentOS 8.  
I have already set up many virtual hosts and they are running smoothly.  
Additionally I have made entries with imaginary domain names in local /etc/hosts file and they are serving normally thanks to Apache names based virtual hosts.

Now I want to serve Docker containers instead of simple html pages.  
All of them are accessible with Docker command -p 8080:80 and more over are accessible with imaginary domain names only if I add port on my web server. For example:  
[Nextcloud.net](http://Nextcloud.net) :8080.

Now I want to access them with our adding the port at the end.  
I found the below code in git hub but is not working for me.

```auto
<VirtualHost *:80>
        ServerAdmin admin@example.com
        DocumentRoot /var/www
        ServerName docker.example.com
        ErrorLog logs/docker.example.com_error.log
        CustomLog logs/docker.example.com_access.log combined
        ProxyPreserveHost On
        ProxyRequests off

        <Location />
                ProxyPass http://localhost:9000/
                ProxyPassReverse http://localhost:9000/
                Order allow,deny
                Allow from all
        </Location>
</VirtualHost>

```

any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![ameinild](https://community.learnlinux.tv/letter_avatar_proxy/v4/letter/a/51bf81/32.png) [@ameinild](https://community.learnlinux.tv/u/ameinild)\
**Post date:** [March 17, 2021, 11:17am UTC](https://community.learnlinux.tv/t/dockers-as-virtual-host-in-apache/314/2 "2021-03-17T11:17:51Z")

</div>

I basically found the same info as you: [Simple Apache reverse proxy example | JamesCoyle.net Limited](https://www.jamescoyle.net/how-to/116-simple-apache-reverse-proxy-example)

But it’s really hard to troubleshoot if you only post the generic example, and not a concrete example of your config. Also, it would be nice to know exactly what is not working.

Could you post an example of the config file exactly as it would be for you (for an imaginary or real service) and also be specific about what errors you get etc. (log output for instance)?

Also please list ‘docker ps’ so we can see your forwarded ports in docker.

---

<div class="post-metadata">

**Author:** ![CptCharis](https://community.learnlinux.tv/letter_avatar_proxy/v4/letter/c/7993a0/32.png) [@CptCharis](https://community.learnlinux.tv/u/CptCharis)\
**Post date:** [March 17, 2021, 4:42pm UTC](https://community.learnlinux.tv/t/dockers-as-virtual-host-in-apache/314/3 "2021-03-17T16:42:01Z")

</div>

This is how I wrote the code inside /etc/http/sites-available. (one of the variations that I have tried already)

```
   <VirtualHost nextcloud1.net>
    DocumentRoot /var/www/html
    ServerName nextcloud1.net
    ErrorLog logs/nextcloud1.net_error.log
    CustomLog logs/nextcloud1.net_access.log combined
    ProxyPreserveHost On
    ProxyRequests off

    <Location />
            ProxyPass http://localhost:8080/
            ProxyPass http://localhost:8080/
            Order allow,deny
            Allow from all
    </Location>
 </VirtualHost>

```

I’m receiving this error:

# Service Unavailable

The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

---

<div class="post-metadata">

**Author:** ![CptCharis](https://community.learnlinux.tv/letter_avatar_proxy/v4/letter/c/7993a0/32.png) [@CptCharis](https://community.learnlinux.tv/u/CptCharis)\
**Post date:** [March 17, 2021, 5:16pm UTC](https://community.learnlinux.tv/t/dockers-as-virtual-host-in-apache/314/4 "2021-03-17T17:16:46Z")

</div>

If I type in browser

[nextcloud1.net:8080](http://nextcloud1.net:8080)  
page is serving normally. (/etc/hosts entry include [nextcloud1.net](http://nextcloud1.net))

---

<div class="post-metadata">

**Author:** ![ameinild](https://community.learnlinux.tv/letter_avatar_proxy/v4/letter/a/51bf81/32.png) [@ameinild](https://community.learnlinux.tv/u/ameinild)\
**Post date:** [March 17, 2021, 8:11pm UTC](https://community.learnlinux.tv/t/dockers-as-virtual-host-in-apache/314/5 "2021-03-17T20:11:35Z")

</div>

Without being entirely sure, I would think reverse proxy works only on subdomains, so it should be [nextcloud.home.net](http://nextcloud.home.net) (or something similar).

I’m not aware how reverse proxy works “directly” on main domains ([nextcloud1.net](http://nextcloud1.net)).

What happens if you put the server’s IP address instead of localhost in the proxypass?

Besides, I’m not familiar with Apache, so this is completely random troubleshooting for my part. 😉

---

<div class="post-metadata">

**Author:** ![hulxmash](https://community.learnlinux.tv/letter_avatar_proxy/v4/letter/h/e9c0ed/32.png) [@hulxmash](https://community.learnlinux.tv/u/hulxmash)\
**Post date:** [March 18, 2021, 12:37am UTC](https://community.learnlinux.tv/t/dockers-as-virtual-host-in-apache/314/6 "2021-03-18T00:37:14Z")

</div>

I’m not sure if this is a typo on here or not but you don’t have the ProxyPassReverse line on your location settings. I’m not even a little familiar with reverse proxy in apache so I’m not sure if this was intentional or not.

---

<div class="post-metadata">

**Author:** ![ameinild](https://community.learnlinux.tv/letter_avatar_proxy/v4/letter/a/51bf81/32.png) [@ameinild](https://community.learnlinux.tv/u/ameinild)\
**Post date:** [March 18, 2021, 7:58am UTC](https://community.learnlinux.tv/t/dockers-as-virtual-host-in-apache/314/7 "2021-03-18T07:58:03Z")

</div>

> [@hulxmash](#):
>
> I’m not sure if this is a typo on here or not but you don’t have the ProxyPassReverse line on your location settings.

Good catch - of course one of the lines need to be ProxyPassReverse.
