There are lots of options when it comes to choosing a proxy solution for your Apache Tomcat servers, Apache HTTPD, HAProxy, and NGiNX are currently some of the most commonly used all around open source solutions.
In this quick tutorial we are going to show you how to configure Apache HTTPD as a reverse proxy for Apache Tomcat Server. The Apache HTTPD Server going to redirect all the traffics coming on port 80 to Apache Tomcat Server on port 8080
This tutorial assumes that you have already installed Apache Tomcat Server, if you don’t have it installed yet, you can check out this tutorial
How to install Apache Tomcat 9 Server on CentOS 7 / RHEL 7
– To install Apache Server use the below commands:
# yum install httpd # On centOS / RHEL # apt install apache2 # On Ubuntu
– Enable and start Apache on system boot:
# sudo systemctl start httpd && sudo systemctl enable httpd # On centOS / RHEL # sudo systemctl start apache2 && sudo systemctl enable apache2 # On Ubuntu
– Let’s a create a new Apache vhost file called tomcat.conf as below or you can edit the default Apache configuration file
<virtualhost *:80> ServerName yallalabs.local # YOUR DOMAIN NAME ServerAlias www.yallalabs.local ServerAdmin firstname.lastname@example.org ProxyRequests Off ProxyPass / http://localhost:8080/ ProxyPassReverse / http://localhost:8080/ # YOUR TOMCAT IP ADDRESS </virtualhost>
– Run the following command to test the configuration file for syntactic validity
# httpd -t # On CentOS / RHEL # apache2ctl configtest # On Ubuntu
– Finally, run one of the following commands to reload the new vhost Configuration:
# httpd -k graceful # On CentOS / RHEL # apache2ctl -k graceful # On Ubuntu
– If you installed Apache on CentOS 7 or RHEL 7 and the Selinux is enabled you need to execute the following command:
# setsebool -P httpd_can_network_connect=1
We hope this tutorial was enough helpful. If you need more information, or have any questions, just comment below and we will be glad to assist you!
PS. If you like this post please share it with your friends on the social networks using the buttons below.Thanks.