How to Set up a Reverse Proxy
A proxy is an application that processes resource requests between client computers and servers. A reverse proxy retrieves those resources from the servers on behalf of the clients, just as if the resources came directly from the servers.
Reverse proxies have a variety of specific applications, especially for web servers. A single computer may need to run multiple web servers where each server listens to incoming service requests on a different port. A reverse proxy can then analyze each request and deliver it to the appropriate server. For example, a CentOS computer running Apache and Tomcat servers can use a reverse proxy to allow Tomcat to request resources from Apache.
DIFFICULTY | Basic - 1 | Medium - 2 | Advanced - 3 |
TIME REQUIRED | 15 min |
RELATED PRODUCTS | Linux-based VPS or dedicated servers |
Here is a quick tutorial on how to setup a reverse proxy between an Apache web server and a Tomcat server. If you need any help setting up Tomcat, see How to install Apache Tomcat.
Start the servers
Use the following commands to start Apache and Tomcat from the command line if they aren't already running:
# sudo $CATALINA_HOME/bin/startup.sh
These commands should provide the following output:
Modify httpd.conf
Use nano to modify the httpd.conf, which is typically located in /etc/httpd/conf
. Add the following lines to httpd.conf
in the indicated section for loading modules:
The above lines will create the reverse proxy to the Tomcat server from http://localhost/test, assuming that Tomcat is listening to the default port of 8080.
Save httpd.conf
, which should now appear similar to the following screenshot:
Test the reverse proxy
Enter http://localhost/test in your browser. You should see the default Tomcat homepage as follows: