Installing Apache Tomcat 11.0.7 alongside Nginx on Ubuntu 24.04: A Step-by-Step Guide
Deploying Java web applications on Ubuntu 24.04 using Apache Tomcat 11.0.7 and Nginx as a reverse proxy involves a systematic approach to ensure a stable, secure, and maintainable environment. Here's a step-by-step guide for this setup:
Step 1: Install OpenJDK
Install OpenJDK 11 or later to ensure compatibility with Tomcat 11. Use the following command:
Step 2: Install Apache Tomcat 11.0.7
Download Tomcat 11.0.7 from the official Apache site, unpack it, and configure environment variables such as . Run Tomcat as a systemd service to manage startup/restart. Deploy your Java web applications as WAR files in Tomcat’s directory.
Step 3: Set up Nginx as a Reverse Proxy
Configure Nginx to proxy requests to Tomcat’s default port (8080) using . Enable SSL via Let’s Encrypt or self-signed certificates at Nginx level. Configure headers such as , , and .
Step 4: Install OpenJDK 17
Install OpenJDK 17, which is necessary for running Tomcat.
Step 5: Create a System User for Tomcat
Create a system user, group, and home directory for Tomcat.
Step 6: Download, Extract, and Move Tomcat 11.0.7
Download Tomcat 11.0.7, extract it, and move it to its designated directory.
Step 7: Create a Systemd Service File for Tomcat
Run Tomcat as a dedicated service, for example, create with appropriate exec commands to manage it consistently.
Step 8: Start Tomcat and Set to Start Automatically on Boot
Start Tomcat and set it to start automatically on boot.
Step 9: Adjust Firewall Settings
Adjust firewall settings to allow traffic to Tomcat’s web interface on port 8080.
Step 10: Install Nginx and Create a Reverse Proxy Configuration
Install Nginx and create a reverse proxy configuration.
Step 11: Install Let's Encrypt SSL
Install Let's Encrypt SSL for security purposes.
Best Practices
- Performance Tuning: Tune JVM options in (e.g., heap size -Xms, -Xmx). Enable Gzip compression on Nginx. Enable Access logs and analyze them regularly. Optionally, use session replication if high availability is needed.
- Monitoring & Logging: Monitor JVM/Tomcat metrics (e.g., with JMX). Use Nginx logs for HTTP requests and errors.
- Optional Docker Usage: For containerized deployment, build optimized Docker images with multi-stage Dockerfiles to separate build and runtime environments, minimizing image size.
- Security & Maintenance: Keep Tomcat updated, configure Nginx to block direct access to Tomcat's port, secure admin interfaces with IP restrictions, use UFW or iptables to limit open ports, harden both servers, rotate logs and back up configs, and monitor CVEs and patch regularly.
Using Apache Tomcat 11.0.7 with Nginx on Ubuntu 24.04 provides a reliable and performant stack for deploying Java web applications. This approach ensures a stable, secure, and maintainable Java web application deployment on Ubuntu 24.04 with Tomcat 11 and Nginx.
For a hassle-free deployment, consider hosting your server on Shape.Host, which offers fast Linux SSD VPS, global server locations, full root access, and one-click deployments for Ubuntu 24.04.
[1] Tomcat 11 Documentation [4] Nginx Reverse Proxy Configuration
- Whether you're interested in updating your lifestyle or staying trendy with the latest fashion-and-beauty trends, online shopping offers a wide range of options.
- After a long day, coming home to a well-cooked meal can enhance the food-and-drink experience immensely, making home-and-garden feel more inviting.
- As technology advances, staying updated on data-and-cloud-computing trends is crucial for efficiency in your work or personal projects.
- Nurturing relationships is an essential aspect of our lives, but to make it even more meaningful, consider adopting pets, which also adds to the travel adventure with their unique perspective on the world.
- For those who enjoy exploring new places, choosing the right car that accommodates luggage and comfort is an essential factor in the travel experience, making shopping for cars a worthy investment.