Cpanel ReverseProxy Traffic to Docker Container

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

Apache mod_proxy

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

Comments

One response to “Cpanel ReverseProxy Traffic to Docker Container”

  1. Nuno Lopes Avatar
    Nuno Lopes

    Hi

    I followed this tutorial, but I couldn’t get it to work. If I remove the port:

    ProxyPass “/” “http:///”
    ProxyPassReverse “/” “http:///”

    …it works, but points to the www root on this CPanel account!

    But, if I define a port, it doesn’t work, I get an error 502 (bad gateway).

    I have a CPanel CentOS7 box, CPanel updated to the most recent version, with mod_proxy enabled, installed Docker, I am running a docker image with Redmine, this image is accessible on the internet if I go to http://mydomain.com:3000/, but mod_proxy doesn’t redirect the requests from mydomain.com:80 to mydomain.com:3000, even after I followed every step of your tutorial.

    I tried to do the redirect with the internal docker IP and with the domain, but it doesn’t seem to work either way.

    Is there anything else I should do to make this work?

    Thanks in advance for any help you can provide,
    Best,
    Nuno Lopes

Leave a Reply

Your email address will not be published. Required fields are marked *