How to Install Jetty on Ubuntu 22.04

install jetty on ubuntu 22.04

Jetty or Eclipse Jetty is a Java web server and Java servlet container. Jetty is free and open-source software used to establish communication from one machine to another, unlike the usual web servers that serve documents from server to user.

In this blog post, we will install Jetty with Apache as a reverse proxy and will secure the connection with Free Let’s Encrypt SSL certificate. Let’s get started!

Prerequisites

  • A server with Ubuntu 22.04 OS
  • A valid domain with pointed A record to the server IP address
  • User privileges: root or non-root user with sudo privileges

Step 1. Update the System

It is recommended to have a fresh installation of Ubuntu 22.04 for this setup. After every fresh installation of the OS, we need to update the system packages to the latest versions available.

sudo apt update -y && sudo apt upgrade -y

Step 2. Install Java OpenJDK 8

The Java OpenJDK version 18 is already included in the Ubuntu 22.04 repo. so we install it we need to execute the following command:

sudo apt-get install openjdk-8-jdk -y

Once installed, execute the following command to check the installed Java version:

java -version

You will receive the following output:

root@host:~# java -version
openjdk version "1.8.0_352"
OpenJDK Runtime Environment (build 1.8.0_352-8u352-ga-1~22.04-b08)
OpenJDK 64-Bit Server VM (build 25.352-b08, mixed mode)

Step 3. Install Jetty 9

To install Jetty 9, execute the following command:

sudo apt-get install jetty9 -y

Once installed, start and enable the jetty service.

sudo systemctl enable jetty9 && sudo systemctl start jetty9

Check if the service is up and running:

sudo systemctl status jetty9

You should receive the following output:

root@host:~# sudo systemctl status jetty9
● jetty9.service - Jetty 9 Web Application Server
     Loaded: loaded (/lib/systemd/system/jetty9.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2022-12-27 16:08:48 CST; 1min 49s ago
       Docs: https://www.eclipse.org/jetty/documentation/current/
   Main PID: 5443 (java)
      Tasks: 25 (limit: 4575)
     Memory: 78.8M
        CPU: 4.176s
     CGroup: /system.slice/jetty9.service
             └─5443 /usr/bin/java -Djetty.home=/usr/share/jetty9 -Djetty.base=/usr/share/jetty9 

The jetty service is running on port 8080. To check this, execute the following command:

netstat -tunlp | grep 8080

You should receive the following output:

root@host:~# netstat -tunlp | grep 8080
tcp6       0      0 :::8080                 :::*                    LISTEN      5443/java

Step 4. Install Apache Web Server

To install Apache, execute the following command:

sudo apt-get install apache2 -y

Once installed, start and enable the service.

sudo systemctl enable apache2 && sudo systemctl start apache2

Check if the service is up and running:

sudo systemctl status apache2

You should receive the following output:

root@host:~# sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2022-12-27 09:38:49 CST; 6h ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 744 (apache2)
      Tasks: 55 (limit: 4575)
     Memory: 10.2M
        CPU: 1.542s
     CGroup: /system.slice/apache2.service
             ├─744 /usr/sbin/apache2 -k start
             ├─787 /usr/sbin/apache2 -k start
             └─788 /usr/sbin/apache2 -k start

Dec 27 09:38:49 host.test.tk systemd[1]: Starting The Apache HTTP Server...
Dec 27 09:38:49 host.test.tk systemd[1]: Started The Apache HTTP Server.

Step 5. Configure Jetty with Apache as a Reverse Proxy

Go into the Apache directory and create a configuration file for the Jetty.

cd /etc/apache2/sites-available/

touch jetty.conf

Open the file, paste the following lines of code, save the file and close it.

<VirtualHost *:80>
ServerName yourdomain.com
DocumentRoot /var/www/html/

<Directory /var/www/html>
AllowOverride All
</Directory>

ProxyRequests off
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

Enable the Apache configuration for Jetty and rewrite the module.

a2dissite 000-default.conf

a2enmod proxy

a2enmod proxy_http

sudo a2enmod rewrite

sudo a2ensite jetty.conf

Check the syntax:

apachectl -t

You should receive the following output:

root@vps:~# apachectl -t
Syntax OK

If the syntax is OK, restartd the Apache service.

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS
systemctl restart apache2

Once the Apache service is restarted, you can access Jetyy via your domain at http://yourdomain.com

Step 6. Install Free Let’s Encrypt SSL certificate

To install the Free Let’s Encrypt SSL certificate first install the Certbot:

sudo apt-get install certbot python3-certbot-apache -y

Once installed, generate the certificate with the following command:

certbot --apache -d yourdomain.com

In the next steps, you need to add your email, confirm the license agreements, not share your email address and etc.

root@host:/etc/apache2/sites-available# certbot --apache -d yourdomain.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): admin@yourdomain.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.3-September-21-2022.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: N
Account registered.
Requesting a certificate for yourdomain.com

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/yourdomain.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/yourdomain.com/privkey.pem
This certificate expires on 2023-03-27.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

Deploying certificate
Successfully deployed certificate for yourdomain.com to /etc/apache2/sites-available/jetty-le-ssl.conf
Congratulations! You have successfully enabled HTTPS on https://yourdomain.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
 * Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
 * Donating to EFF:                    https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Now, you can access your Jetty service securely at https://yourdomain.com.

That’s it. You successfully installed and configured Jetty with Apache as a reverse proxy. If you find this setup difficult, you can always contact our technical support, and they will do the rest. We are available 24/7, and we are ready to help you. You just need to sign up for one of our NVMe VPS plans and submit a support ticket.

If you liked this post about installing Jetty on Ubuntu 22.04, please share it with your friends on social networks using the buttons on the left or simply leave a reply below.

Leave a Comment