Dockers as virtual host in Apache

CptCharis

Well-Known Member
Joined
Feb 27, 2018
Messages
562
Reaction score
463
Credits
970
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 :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.

Code:
<VirtualHost *:80>
        ServerAdmin [email protected]
        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.
 


f33dm3bits

Gold Member
Gold Supporter
Joined
Dec 11, 2019
Messages
4,779
Reaction score
3,433
Credits
34,795
Using your example, 8080:80, means that you map port 80 running in the docker container to port 8080 on the docker host. Which means that the container is reachable on the host on port 8080, you would then have to use that port in your virtualhost. So it would be using 8080 instead of 9000, try this.
Code:
<VirtualHost *:80>
        ServerAdmin [email protected]
        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:8080/
                ProxyPassReverse http://localhost:8080/
                Order allow,deny
                Allow from all
        </Location>
</VirtualHost>
[/CODE}
 
OP
CptCharis

CptCharis

Well-Known Member
Joined
Feb 27, 2018
Messages
562
Reaction score
463
Credits
970
I did this
Code is an example as I found it on the web
 

f33dm3bits

Gold Member
Gold Supporter
Joined
Dec 11, 2019
Messages
4,779
Reaction score
3,433
Credits
34,795
It may differ per application what is needed under ProxyPass and ProxyPassReverse, I would look it up in the documentation of the docker images you are trying to run since most applications document that now days.
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Linux.org Hosting Donations
Consider making a donation

Members online


Top