Setting Up a Reverse Proxy on cPanel/WHM for Port 8081
This guide explains how to configure Apache on a cPanel/WHM server to reverse proxy traffic to a backend service running on port 8081.
1. Create a Custom Reverse Proxy Configuration
Create the directory for custom Apache configurations:
mkdir -p /etc/apache2/conf.d/userdata/ssl/2_4/cPanelusername/domain.tld/
Replace `cPanelusername` with your cPanel account username and `domain.tld` with your actual domain.
2. Create and Edit the Reverse Proxy Configuration File
vim /etc/apache2/conf.d/userdata/ssl/2_4/cPanelusername/domain.tld/rproxy.conf
Paste the following content:
##### Backend Reverse Proxy - Port 8081 ##### ProxyRequests Off ProxyPass / http://localhost:8081/ ProxyPassReverse / http://localhost:8081/ ##### Backend Reverse Proxy - Port 8081 #####
This configuration tells Apache to forward all requests to `localhost:8081`.
Save and exit (`:wq` in `vim`).
3. Validate and Apply Changes
Check the Apache Configuration for Errors:
httpd -t
If there are no syntax errors, proceed.
4. Rebuild and Restart Apache
Run the following commands to apply the changes:
/scripts/rebuildhttpdconf /scripts/restartsrv_apache
5. Verify Your Setup
Try accessing your domain in a browser.
If you face issues, check the Apache error logs:
tail -f /var/log/apache2/error_log
✅ Done! Apache is now reverse proxying traffic to port 8081 on your cPanel/WHM server. 🚀