Jetty has moved!
Jetty is a project at the Eclipse Foundation.
Jetty Powered:
Contact the core Jetty developers at
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery
Skip to end of metadata
Go to start of metadata

Configuring Apache mod_proxy with Jetty

The apache web server is frequently used as a server in front of a servlet container.
While there are no real technical reasons to front Jetty with apache, sometimes this is needed
for software load balancing, or to fit with a corporate infrastructure, or simply to stick with a known deployment structure.

There are 3 main alternative for connection Apache to Jetty:

  1. Using apache mod_proxy and an normal Jetty HTTP connector.
  2. Using apache mod_proxy_ajp and the Jetty AJP connector.
  3. Using apache mod_jk and the Jetty AJP connector.

Using the HTTP Connectors is greatly preferred, as Jetty performs significantly better with HTTP and the AJP protocol is poorly documented and there are many version irregularities. If AJP is to be used, the then mod_proxy_ajp module is preferred over mod_jk. Previously, the load balancing capabilities of mod_jk meant that it had to be used (tolerated), but with apache 2.2, mod_proxy_balancer is available and load balance over HTTP and AJP connectors.


Apache has a mod_proxy module available for almost all versions of apache. However, prior to apache 2.2, only reverse proxy features were available and mod_proxy_balancer was not available for load balancing.

Documentation for mod_proxy is available for:

Configuration as a Reverse Proxy

The configuration file layout for apache varies greatly with version and distribution, but to configure mod_proxy as a reverse proxy, the follow configuration is key:

  1. Jetty needs to be configured with a normal HTTP connector, probably on port 8080 or similar.
  2. The proxy module (and other proxy extension used) must be loaded:

    Apache 2.2 normally bundles mod_proxy, mod_proxy_ajp and mod_proxy_balancer, so they often do not need to be installed separately. If they are separately bundled by your operation system (eg as RPMs or debians) ensure that they are installed.
  3. Forward proxy needs to be turned off:
  4. Reverse proxy paths must be configured with URL of the jetty server:
  5. Frequently apache documentation will instruct that ProxyPassReverse configuration be used so that apache can rewrite any URLs in headers etc. However, if you use the ProxyPreserveHost configuration, Jetty can generate the correct URLs and they do not need to be rewritten:
    Alternatively, since Jetty 6.1.10, instead of preserving the host and to retrieve the client remote address in the webapp (ServletRequest#getRemoteAddr()) you can use the forwarded property on AbstractConnector which interprets the mod_proxy_http "x-forwarded-" headers instead:
    Or, to force the result of ServletRequest#getServerName() and ServletRequest#getServerPort() (if headers are not available):

  6. It is also very useful to turn on proxy status monitoring (see management below):

Proxying SSL on Apache to HTTP on Jetty

The situation here is:

If you want to offload the SSL onto Apache, and then use plain http requests to your Jetty backend, you need to configure Jetty to use https:// in all redirected requests.

You can do that by extending the Connector class of your choice, eg the SelectChannelConnector, and implement the customize(EndPoint, Request) method to force the scheme of the Request to be https like so ( don't forget to call super.customize(endpoint,request)! ):

If you need access on Jetty to some of the SSL information accessible on Apache, then you need to some configuration tricks on Apache to insert the SSL info as headers on outgoing requests. Follow the Apache configuration suggestions on this tutorial which shows you how to use mod_headers to insert the appropriate request headers. Of course you will also need to code your application to look for the corresponding custom request headers bearing the ssl information.


With apache 2.2 mod_proxy is able to use the extension mod_proxy_balancer


The configuration of mod_proxy_balancer is similar to pure mod_proxy, except that balancer:// URLs may be used as a protocol instead of http:// when specifying destinations (workers) in ProxyPass elements.

Proxy balancer:// - defines the nodes (workers) in the cluster. Each member may be a http:// or ajp:// URL or another balancer:// URL for cascaded load balancing configuration.
If the worker name is not set for the Jetty servers, then session affinity (sticky sessions) will not work. The JSESSIONID cookie must have the format <sessionID>.<worker name>, in which worker name has the same value as the route specified in the BalancerMember above (in this case "jetty1" and "jetty2"). See this article for details. The following can be added to the jetty-web.xml in the WEB-INF directory to set the worker name.


Apache provide mod_status and Balancer Manager Support so that the status of the proxy and balancer can be viewed on a web page. The following configuration enables these UIs at /balancer and /status URLs:

These UIs should be protected from external access.

  • No labels

1 Comment

  1. neekfenwick ok.. i found that i have to add retry=0 to the ProxyPass line, else when you stop Jetty, mod_proxy immediately returns 502, then repeated 503's, to web clients, even if jetty is restarted
    neekfenwick you have to stop/start httpd to make mod_proxy get over itself
    neekfenwick retry=0 fixes this behaviour, so 502 is not sent.. stopping jetty results in mod_proxy giving repeated 503 to client, and starting jetty re-establishes comms ok

Contact the core Jetty developers at
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery