- Lab
- A Cloud Guru
Set up Apache as a Proxy to Tomcat
Welcome to this hands-on lab for setting up an Apache web server as a proxy front end to Tomcat, a Java-based application platform built around deploying and managing Java Web Applications. The provided server is running Red Hat Enterprise 8. Tomcat 9 is pre-installed and available for you on port **8080** at the server's public IP address. You will be tasked with making Tomcat available on port **80** via the Apache httpd server. Once you have completed the task you will need to test, to ensure you can connect via port **80** and access the Tomcat GUI.
Path Info
Table of Contents
-
Challenge
Test to Ensure You Can Access the Preconfigured Tomcat Instance by Using the Server's Public IP Address and Port 8080
It may take from 3 to 10 minutes after the hands-on lab has started before you can access the Tomcat server on port 8080.
To access the server, copy the external IP address (from the hands-on lab overview page) and test in your browser by using this IP address and appending :8080 to it.
For example, if the IP address shown was 3.92.152.3 then you would put the following URL into your web browser:
http://3.92.152.3:8080
You should be able to see the GUI.
-
Challenge
Install the Apache Web Server onto the Provided Lab Server
Log into the server's console and install the Apache web server:
sudo dnf install httpd sudo systemctl enable httpd sudo systemctl start httpd
Go to a browser and test that the Apache web server is working. You should see the default Apache web page.
-
Challenge
Configure the Apache Web Server, via Virtual Host Setup, as a Proxy to the Tomcat Instance
Create a virtual host entry inside an Apache configuration file. This file should be called
tomcat_manager.conf
:sudo vim /etc/httpd/conf.d/tomcat_manager.conf
You can use the following as an example of what needs to be inside this configuration file:
<VirtualHost *:80> ServerAdmin root@localhost ServerName myserversystem.mylabserver.com DefaultType text/html ProxyRequests on ProxyPreserveHost On ProxyPass / http://localhost:8080/ ProxyPassReverse / http://localhost:8080/ </VirtualHost>
-
Challenge
Either Disable or Change SELinux so That the Proxy Will Work
SELinux is enabled on the hands-on lab server. You can choose to disable it or adjust it so it will allow the Apache web server to act as a proxy.
To disable SELinux you would do the following:
sudo setenforce permissive
Then edit the SELinux configuration file to make the server permissive:
sudo vim /etc/selinux/config
Once in the editor, change this line:
SELINUX=enforcing
Make it
permissive
, instead ofenforcing
:SELINUX=permissive
Then save the file.
If you wish to keep SELinux enabled and allow it to permit the Apache web server to work as a proxy, you would run the following commands:
sudo setsebool -P httpd_can_network_connect 1 sudo setsebool -P httpd_can_network_relay 1 sudo setsebool -P httpd_graceful_shutdown 1 sudo setsebool -P nis_enabled 1
-
Challenge
Restart the Apache Web Server and Look for Errors
Restart the Apache web server and check for errors:
systemctl restart httpd
If there are errors and Apache does not start, then troubleshoot those errors.
-
Challenge
Test You Can Access Tomcat via Port 80
You should be able to see the Tomcat GUI being served out on port 80.
If this does not work, or there is an error, troubleshoot the installation.
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.