Introduction

Apache Tomcat is a popular open-source implementation of the Java Servlet, JavaServer Pages, Java Expression Language, and WebSocket technologies. It is widely used for hosting Java-based web applications. Setting up Apache Tomcat with Nginx as a reverse proxy on AlmaLinux 9 allows you to serve Java web applications with improved performance and security. In this guide, we'll walk you through the step-by-step process of installing Apache Tomcat with Nginx reverse proxy on AlmaLinux 9.

Prerequisites

Before you begin, make sure you have the following:

  • An AlmaLinux 9 server with sudo privileges
  • Java Development Kit (JDK) installed on your server

Step 1: Install Apache Tomcat

First, update the package index on your AlmaLinux system:

sudo dnf update

Install Apache Tomcat using the package manager:

sudo dnf install tomcat

Step 2: Configure Apache Tomcat

Start the Apache Tomcat service and enable it to start on boot:

sudo systemctl start tomcat
sudo systemctl enable tomcat

Apache Tomcat should now be running on port 8080.

Step 3: Install Nginx

Install Nginx using the package manager:

sudo dnf install nginx

Step 4: Configure Nginx as a Reverse Proxy

Edit the Nginx configuration file to configure it as a reverse proxy for Apache Tomcat:

sudo nano /etc/nginx/nginx.conf

Add the following configuration inside the http block:

server {
    listen 80;
    server_name your_domain.com; # Change this to your domain name or IP address
    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;
    }
}

Save and close the file. Then, test the Nginx configuration and restart the Nginx service:

sudo nginx -t
sudo systemctl restart nginx

Step 5: Access Apache Tomcat via Nginx

Open a web browser and navigate to your server's domain name or IP address to access Apache Tomcat via Nginx.

Conclusion

Congratulations! You've successfully installed Apache Tomcat with Nginx reverse proxy on AlmaLinux 9. You can now host Java web applications with improved performance and security.

Thank you for reading our guide on how to install Apache Tomcat with Nginx reverse proxy on AlmaLinux 9. We hope you found it helpful!

Was this answer helpful? 0 Users Found This Useful (0 Votes)