Dockers as virtual host in Apache

CptCharis

Well-Known Member
Joined
Feb 27, 2018
Messages
563
Reaction score
465
Credits
982
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
5,952
Reaction score
4,421
Credits
43,723
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
563
Reaction score
465
Credits
982
I did this
Code is an example as I found it on the web
 

f33dm3bits

Gold Member
Gold Supporter
Joined
Dec 11, 2019
Messages
5,952
Reaction score
4,421
Credits
43,723
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.
 

Sky071111

New Member
Joined
May 1, 2023
Messages
9
Reaction score
0
Credits
63
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.
Hi there,
Just the simple command:
/etc/docker/
/etc/default-isc-dhcp-server-server.
/etc/dhcp/dhcpd.conf.
/etc/dhcp/dhcp/conf
/etc/netplan/01-netconfig.yaml

Also when you add a port on your web server try to type for example:
Netcloud.net :8080

Kind regards
 
MALIBAL Linux Laptops

Linux Laptops Custom Built for You
MALIBAL is an innovative computer manufacturer that produces high-performance, custom laptops for Linux.

For more info, visit: https://www.malibal.com

Staff online

Members online


Top