How to install the Jetty Java server with an NGINX reverse proxy

If you are building web-based applications, you might consider using them with the Jetty Java server. Discover how to install this and a NGINX reverse proxy together.

How to install the Jetty Java server with an NGINX reverse proxy
If you are building web-based applications, you might consider serving them with the Jetty Java server. Discover how to install this and a NGINX reverse proxy together.

Jetty is an HTTP server and Java Servlet container for communication from machine to machine within larger software frameworks. Jetty is free, open source and is used in projects such as Apache ActiveMQ, Alfresco, Scalatra, Apache Maven, Google App Engine, Eclipse, Twitter’s Streaming API and more.

Jetty is growing in popularity because it is easy to build in, very lightweight and an option for both static and dynamic content. With Jetty you can run both your web server and web applications in the same process, without suffering from overhead costs and complications.

To demonstrate Jetty’s flexibility, I will guide you through the process of installing Jetty as a Java HTTP server on Ubuntu Server 18.04, using NGINX as a reverse proxy.

SEE: Choose your Windows 7 exit strategy: four options (TechRepublic Premium)

What you need

The only things you need to make this work are:

  • An active, updated copy of Ubuntu Server 18.04

  • A user with sudo rights

How to install Jetty

The first thing to do is install Jetty. Before that can be installed, Java must first be added with the command:

sudo apt-get install default-jdk -y

When that installation is complete, install Jetty with the command:

sudo apt-get install jetty9 -y

Start and enable Jetty with the commands:

sudo systemctl starts jetty9
Switch on sudo systemctl jetty9

How to install and configure NGINX

We must first install NGINX to serve as a reverse proxy for Jetty. Before doing this, you must stop and disable Apache (otherwise NGINX will not be installed). This can be achieved with the commands:

sudo systemctl stop apache2
sudo systemctl disable apache2

With Apache stopped and disabled, install NGINX with the command:

sudo apt-get install nginx -y

Start and enable NGINX with the commands:

sudo systemctl starts nginx
sudo systemctl enables nginx

Create a NGINX virtual host configuration for Jetty with the command:

sudo nano /etc/nginx/sites-available/jetty.conf

Paste the following content into that file:

upstream jetty {
server 127.0.0.1:8080 weight = 100 max_fails = 5 fail_timeout = 5;
}

server {
listen 80;
servername example.com;

place / {
proxy_set_header X-Forwarded-Host $ host;
proxy_set_header X-Forwarded-Server $ host;
proxy_pass http: // jetty /;
}
}

Save and close the file.

Enable the new virtual host with the command:

sudo ln -s /etc/nginx/sites-available/jetty.conf / etc / nginx / sites-enabled /

Restart NGINX with the command:

sudo systemctl restarts nginx

Get access to Jetty

To ensure that your Jetty and NGINX instances are active, open a web browser and point it to http: // SERVER_IP: 8080 (where SERVER_IP is the IP address of the hosting server). You should see the Jetty welcome screen (Figure A).

Figure A

The Jetty welcome screen means that it is ready to serve you.

If the NGINX welcome page appears, you must move that index file with the command:

sudo mv /var/www/html/index.nginx-debian.html ~ /

Restart NGINX and the Jetty page should appear.

And that’s all to install Jetty and use NGINX as a server reverse proxy. You can now start building your sites and applications with this flexible Java server.

Open source weekly newsletter

You do not want to miss our tips, tutorials and comments about the Linux operating system and open source applications.
Delivered Tuesday

Register today

Also see

Getty Images / iStockphoto

Chileans vote for new constitution, leaving behind relic of Pinochet’s brutal legacy

SANTIAGO, Chile — On the wooden benches of Santiago’s Estadio Nacional, university professor Luís Cifuentes spent long, empty days in the spring of 1973 trying to ignore the agonizing screams emanating from the bowels of the stadium.Around 40,000 left-wing political prisoners passed through the stadium during Gen. Augusto Pinochet’s brutal dictatorship (from 1973 to 1990),…

Freshly signed law aims to limit the damage from area weather

Space weather like solar flares could seriously disrupt electronics and satellites, and the US government might soon mount a better defense. President Trump has signed the PROSWIFT Act (Promoting Research and Observations of Space Weather to Improve the Forecasting of Tomorrow), a bill that will help to predict space weather and limit the damage when…

CIO interview: Joe Soule, CTO, Capital One Europe

Never go back, or so they say – but one IT chief’s return to his former employer brought new opportunities and tech transformation By Mark Samuels Published: 21 Oct 2020 11:30 It is a popular adage in employment to say that you should never go back, but Joe Soule, chief technology officer (CTO) at finance…

Leave a Reply