Table of Contents

Install Jetty

This page shows how to install Jetty on a CentOS 6 machine.

Prerequisites

We assume we have already installed and setup nginx to act as a reverse proxy.

For this example, we will assume we are going to deploy an application called myapp.

Download

Download the latest, stable version from the Jetty website. Download the *.tgz file not the *.zip file.

Get this onto the target server in the /tomcat/home directory. At the time of writing, Jetty is installed and run under the user 'tomcat'. We may create its own user at some point in the future or rename the tomcat user to something more generic like 'webapp'.

Extract the file with the commands:

su - tomcat
cd /tomcat/home
tar xf jetty-distribution-9.2.11.v20150529.tar.gz
rm -f jetty-distribution-9.2.11.v20150529.tar.gz
ln -s jetty-distribution-9.2.11.v20150529 jetty

cd /tomcat/home/jetty # Remove files we don't need in the home directory. rm -fr README.TXT license-eplv10-aslv20.html notice.html demo-base webapps

Configure Jetty

Start creating needed directories and files. Change the port number as appropriate.

mkdir -p /tomcat/base/jetty-myapp/webapps
mkdir -p /tomcat/base/jetty-myapp/logs
mkdir -p /tomcat/base/jetty-myapp/properties/myapp
cp /tomcat/home/jetty/start.ini /tomcat/base/jetty-myapp/
sed -i "s/jetty.port=8080/jetty.port=8089/g" /tomcat/base/jetty-myapp/start.ini
cp -R /tomcat/home/jetty/etc/ /tomcat/base/jetty-myapp/
cp /tomcat/home/jetty/bin/jetty.sh /etc/init.d/jetty-myapp

Configure startup script

sed -i "82i JETTY_BASE=/tomcat/base/jetty-myapp" /etc/init.d/jetty-myapp
sed -i "82i JETTY_HOME=/tomcat/home/jetty" /etc/init.d/jetty-myapp
sed -i "82i JETTY_CONF=/tomcat/base/jetty-myapp/etc/jetty.conf" /etc/init.d/jetty-myapp
sed -i "82i JETTY_USER=tomcat" /etc/init.d/jetty-myapp
# Without this, the application won't start up properly.
sed -i "s/SU_SHELL\ -c\ \"/SU_SHELL\ -c\ \"\ cd\ \$JETTY_BASE;/g" /etc/init.d/jetty-myapp
chkconfig --add /etc/init.d/jetty-myapp
chkconfig jetty-myapp on
service jetty-myapp start

This to the top of /etc/nginx/conf.d/default.conf. Ensure the port number matched what you configured in the /tomcat/base/jetty-myapp/start.ini file.

upstream myappbackend {
    server 127.0.0.1:8089;
}

This in the https section (the bit within the server section listening on port 443

    location /myapp/ {
        proxy_pass http://myappbackend/myapp/;
    }
service nginx restart