Question
How do I create a Reverse Proxy in Apache?
Answer
A reverse proxy receives a client's requests for a website and redirects them to a different destination, such as a different port. A proxied request returns the content from that destination as if it were the original destination requested by the client. This is useful for forwarding requests to an application other than Apache, or another server, while still using Apache to serve the request.
Warning: cPanel support cannot perform these actions, and this article is intended only for informational purposes. This task should be performed by a system administrator who is experienced in managing Reverse Proxies in Apache.
To utilize mod_proxy:
- Log in to the server via SSH or WHM's Terminal as the
rootuser. -
Create the directories and files necessary for the vhost includes of the domain you wish to proxy.
# mkdir -vp /etc/apache2/conf.d/userdata/ssl/2_4/CPANELUSERNAME/DOMAIN.TLD/
# mkdir -vp /etc/apache2/conf.d/userdata/std/2_4/CPANELUSERNAME/DOMAIN.TLD/
# touch /etc/apache2/conf.d/userdata/ssl/2_4/CPANELUSERNAME/DOMAIN.TLD/include.conf
# touch /etc/apache2/conf.d/userdata/std/2_4/CPANELUSERNAME/DOMAIN.TLD/include.conf
Note: You must replace CPANELUSERNAME with the cPanel account's username and DOMAIN.TLD with the domain you're configuring.
-
Open both
include.conffiles in your preferred text editor, and add the following template.CONFIG_TEXT: ProxyPass /.well-known !
ProxyPass / http://IP:PORT/
ProxyPassReverse / http://IP:PORT/Note: You must replace IP with the IP address and PORT with the port number you're proxying to. The forward slash represents the URI you wish to proxy.
-
Rebuild the Apache configuration to enable the includes by running the following script.
# /usr/local/cpanel/scripts/rebuildhttpdconf
-
Restart the Apache service to apply the changes.
# /usr/local/cpanel/scripts/restartsrv_httpd
Additional Resources
How to use Apache Includes to add Configuration Directives to a specific domain's VirtualHost
Comments
0 comments
Article is closed for comments.