How to install Jetty and configure virtual host proxy
In this post installation of following components will be described:
- Oracle JDK 1.8 for Armbian
- Jetty server (servlet container)
- Virtual host for jetty server
Oracje JDK 1.8 for Armbian
There is an JDK for ARM processor available at Oracle download page. No JRE however… My orange Pi PC Plus is an 32-bit machine. If you have doubts about the version of your CPU find more info in this stackexchange thread. You can download the JDK with following command:
wget --header "Cookie: oraclelicense=accept-securebackup-cookie" /
http://download.oracle.com/otn-pub/java/jdk/8u91-b14/jdk-8u91-linux-arm32-vfp-hflt.tar.gz
The installation procedure is fully described at DigitalOcean community tutorial.
Jetty installation
Installation procedure for Jetty may be found at Jetty 9.3.0.v20150612 documentation. Please check if there is new version of Jetty. As there is already Oracle JDK installed we don’t need to install OpenJDK 7.
Notes for Jetty installation
While configuring Jetty base directory you may want to add support for JSP and JSTL:
java -jar /opt/jetty/jetty-distribution-9.3.0.v20150612/start.jar \
--add-to-start=deploy,http,logging,jsp,jstl
Please check /etc/default/jetty
file. It should contain the line for JETTY_USER
:
JETTY_HOME=/opt/jetty/current
JETTY_BASE=/mnt/sdcard2/jetty/base
JETTY_USER=jetty
TMPDIR=/mnt/sdcard2/jetty/temp
Be also aware that after copying Jetty script to /etc/init.d/jetty
the proper command to check configuration is sudo service jetty check
(there is an
error in documentation).
If Jetty service fails to start please check the permissions for all Jetty folders.
Jetty logs are placed in Jetty base directory and therefore they should probably be linked at /var/log/jetty
.
Apache HTTP virtual host proxy
For a proxy to Jetty server two modules need to be enabled:
user@pi:/opt# sudo a2enmod proxy
user@pi:/opt# sudo a2enmod proxy_http
user@pi:/opt# sudo service apache2 restart
The next thing we need is virtual host configuration. Let’s go into /etc/apache2/sites-available
folder and create the file 010-jetty.conf
with following content:
<VirtualHost *:80>
ServerName jetty.pi.example.com
ServerAlias www.jetty.pi.example.com
ProxyRequests Off
ProxyVia Block
ProxyPreserveHost On
CustomLog /var/log/apache2/jetty.pi.example.com-access.log combined
ErrorLog /var/log/apache2/jetty.pi.example.com-error.log
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
Then the new site needs to be enabled: sudo a2ensite
(you will be asked which site to enable).
Although I did not need this, sometimes additional config may be needed for X-Forwarded-For header