@JS's Notes

Site with notes from my work.

Jetty - Java HTTP server on Debian 10

2019-10-13 System Programing @JS

Jetty is a free and open-source Java HTTP server. Jetty has a small footprint, is embeddable, full-featured and supports SPDY, WebSocket, OSGi, JNDI, JAAS and many other integrations.

Requirements: user with root privileges or non-root user with sudo privileges.

Update your operating system packages and install Java on your system:

$ sudo apt update && sudo apt upgrade -y
$ sudo apt install default-jdk -y
$ java --version
# You should get the following output:
openjdk 11.0.4 2019-07-16
OpenJDK Runtime Environment (build 11.0.4+11-post-Debian-1deb10u1)
OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Debian-1deb10u1, mixed mode, sharing)

By default, Jetty is available in the Debian 10 default repository:

$ sudo apt install jetty9 -y
$ systemctl status jetty9.service
Configure Nginx as a reverse proxy for Jetty
$ sudo apt install nginx -y
$ systemctl status nginx.service

Create a Nginx virtual host file /etc/nginx/sites-available/ctx03vm.local.lnxorg.conf. For the purpose of this tutorial, I will use ctx03vm.local.lnxorg domain, you can change it to the domain you want to use.

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

server {
  listen          80;
  server_name     ctx03vm.local.lnxorg;

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

Check Nginx for any syntax error:

$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successfu

Enable the site and reload Nginx:

$ sudo ln -s /etc/nginx/sites-available/ctx03vm.local.lnxorg.conf  /etc/nginx/sites-enabled/
$ sudo systemctl restart nginx.service
$ systemctl status nginx.service

Open your web browser and type the URL of your Jetty virtual host address.

Reference: eclipse jetty.