Introduction
Apache Tomcat is an open-source Java Servlet Container developed by the Apache Software Foundation. Nginx is a high-performance web server and reverse proxy. This tutorial will guide you through the process of installing Apache Tomcat with Nginx acting as a reverse proxy on AlmaLinux 9.
Prerequisites
Before you begin, ensure you have:
- An AlmaLinux 9 server
- Root or sudo access to the server
- Basic knowledge of Linux command line
Step 1: Install Java Development Kit (JDK)
Apache Tomcat requires Java to be installed on your system. Install OpenJDK 11:
sudo dnf install java-11-openjdk-devel -y
Step 2: Install Apache Tomcat
Install Apache Tomcat using the official package:
sudo dnf install tomcat -y
Step 3: Start Apache Tomcat Service
Start the Apache Tomcat service and enable it to start on boot:
sudo systemctl start tomcat
sudo systemctl enable tomcat
Step 4: Install Nginx
Install Nginx using the official package:
sudo dnf install nginx -y
Step 5: Configure Nginx as Reverse Proxy for Apache Tomcat
Create a new server block configuration file for Nginx:
sudo nano /etc/nginx/conf.d/tomcat.conf
Add the following content:
server {
listen 80;
server_name your_domain.com;
location / {
proxy_pass http://localhost:8080/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Test Nginx configuration for syntax errors:
sudo nginx -t
If the test is successful, reload Nginx to apply the changes:
sudo systemctl reload nginx
Step 6: Access Apache Tomcat via Nginx
Open your web browser and navigate to http://your_domain.com
. You should see the Apache Tomcat default landing page, indicating that Nginx is successfully acting as a reverse proxy for Apache Tomcat.
Conclusion
Congratulations! You have successfully installed Apache Tomcat with Nginx acting as a reverse proxy on AlmaLinux 9. You can now deploy Java web applications and access them via Nginx.