Introduction

Apache Tomcat is an open-source implementation of the Java Servlet, JavaServer Pages, Java Expression Language, and Java WebSocket technologies. Nginx is a high-performance web server that can also be used as a reverse proxy. This tutorial will guide you through the process of installing Apache Tomcat 10 with Nginx acting as a reverse proxy on Debian 12.

Prerequisites

Before you begin, ensure you have:

  1. A Debian 12 server
  2. Root or sudo access to the server
  3. 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 apt update
sudo apt install default-jdk -y

Step 2: Install Apache Tomcat

Download and install Apache Tomcat 10:

cd /tmp
wget https://downloads.apache.org/tomcat/tomcat-10/v10.0.16/bin/apache-tomcat-10.0.16.tar.gz
sudo tar -xf apache-tomcat-10.0.16.tar.gz -C /opt

Step 3: Configure Apache Tomcat

Configure Apache Tomcat to run as a service:

sudo nano /etc/systemd/system/tomcat.service

Add the following content:

[Unit]
Description=Apache Tomcat Web Application Container
After=network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/default-java
Environment=CATALINA_PID=/opt/apache-tomcat-10.0.16/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/apache-tomcat-10.0.16
Environment=CATALINA_BASE=/opt/apache-tomcat-10.0.16

ExecStart=/opt/apache-tomcat-10.0.16/bin/startup.sh
ExecStop=/opt/apache-tomcat-10.0.16/bin/shutdown.sh

User=root
Group=root
Restart=always

[Install]
WantedBy=multi-user.target

Save and close the file, then reload systemd:

sudo systemctl daemon-reload

Start and enable Apache Tomcat:

sudo systemctl start tomcat
sudo systemctl enable tomcat

Step 4: Install and Configure Nginx

Install Nginx:

sudo apt install nginx -y

Create a new server block configuration file:

sudo nano /etc/nginx/sites-available/tomcat

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;
    }
}

Activate the server block by creating a symbolic link:

sudo ln -s /etc/nginx/sites-available/tomcat /etc/nginx/sites-enabled/

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 5: 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 10 with Nginx acting as a reverse proxy on Debian 12. You can now deploy your Java web applications and access them via Nginx.

 

VPS Windows Server

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