On a cpanel server, i need to run a web application using docker container.
Application running side docker container listening on port 8000 on localhost.
For a web site to serve traffic from this docker container, we can use Apache mod_proxy, this is enabled by default on cpanel servers.
https://httpd.apache.org/docs/2.4/howto/reverse_proxy.html
You can verify it at
WHM > EasyApache 4 > Currently Installed Packages > Customize > Apache Modules
For the site, you need to create reverse proxy, create a folder.
NOTE: Replace CPANEL_USER and DOMAIN with your actual cpanel user name and domain name. You can find/verify this path by looking virtual host entry for your domain name in /etc/apache2/conf/httpd.conf file. By default this “Include” line will be commented. Once you put a file and rebuildhttpdconf, this line get uncommented.
mkdir -p /etc/apache2/conf.d/userdata/std/2_4/CPANEL_USER/DOMAIN/
Now create a file
vi /etc/apache2/conf.d/userdata/std/2_4/CPANEL_USER/DOMAIN/docker.conf
Add following.
ProxyPass "/" "http://localhost:8000/" ProxyPassReverse "/" "http://localhost:8000/"
Now rebuild Apache config.
/scripts/rebuildhttpdconf
Now if you check Apache config file (/etc/apache2/conf/httpd.conf), you will see included in Apache virtual host entry.
Restart Apache
service httpd restart
Now if you visit the site, you will see the web application running on http://localhost:8000/
See Reverse proxy, Cpanel Server, Apache
Leave a Reply