Redirecting Requests from Apache to Jetty

Posted on Sun 05 November 2017 in Sysadmin

Assuming you are running an Apache server with a virtual host for abs.mydomain.com, put this into the virtual host's .conf file to redirect all traffic to a Jetty web server running locally behind your Apache:

<Proxy *>
    Order deny,allow
    Allow from all
</Proxy>

ProxyPass / http://localhost:1234/ retry=1
ProxyPassReverse / http://localhost:1234/
ProxyVia On

Here, 1234is the port on which the Jetty server is listening. This port should be blocked from direct access via Apache. Using Ubuntu's default firewall ufw, this can be done by running a simple sudo ufw deny 1234 on the command line.

Added benefit: the internal Jetty server does not need to use SSL if the Apache server provides an SSL connection to the client.

See this SO answer for an explanation of the ProxyPassReverse directive.