Skip to content

Linux VPS & VPS Windows Setup Guide | NetCloud24 Apache Tomcat with Nginx Reverse Proxy on Ubuntu 22.04

Cloud Infrastructure Expert
Linux VPS & VPS Windows Setup Guide | NetCloud24 Apache Tomcat with Nginx Reverse Proxy on Ubuntu 22.04

Introduction

Apache Tomcat is an open-source web server and servlet container. 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 Ubuntu 22.04.

Prerequisites

Before you begin, ensure you have:

  1. An Ubuntu 22.04 server
  2. Root or sudo privileges

Step 1: Install Apache Tomcat

Install Apache Tomcat using the following command:

sudo apt update
sudo apt install -y tomcat9

Step 2: Install Nginx

Install Nginx using the following command:

sudo apt install -y nginx

Step 3: Configure Apache Tomcat

Open the Tomcat server configuration file:

sudo nano /etc/tomcat9/server.xml

Update the following line to allow Tomcat to listen on localhost:

<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" address="127.0.0.1" />

Save and close the file.

Step 4: Configure Nginx as Reverse Proxy

Create a new Nginx configuration file for Tomcat:

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

Add the following configuration to the file:

server {
    listen 80;
    server_name your_domain.com;

    location / {
        proxy_pass http://127.0.0.1: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. Create a symbolic link to enable the site:

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

Test Nginx configuration and restart the service:

sudo nginx -t
sudo systemctl restart nginx

Step 5: Access Apache Tomcat via Nginx

Open a web browser and navigate to your domain (e.g., http://your_domain.com) to access Apache Tomcat via Nginx.

Conclusion

Congratulations! You have successfully installed Apache Tomcat with Nginx acting as a reverse proxy on Ubuntu 22.04. You can now deploy and manage your Java web applications using Tomcat with the added benefits of Nginx as a reverse proxy.

Windows VPS Deutschland

Windows VPS España

Windows VPS Nederland

Windows VPS Italia

Windows VPS Portugal

VPS Windows Italia

Windows VPS

Windows VPS

Windows VPS Sverige

Windows VPS Norge

Windows VPS

Windows VPS Türkiye

Windows RDS (Remote Desktop Services)

Windows VPS

Explore more

More on this topic

Netcloud24
Netcloud24
Cloud Infrastructure Expert · NetCloud24

Comments are closed.