Dashboard > Jetty > ... > Jetty Documentation > Configuring mod_proxy
Configuring mod_proxy Log In | Sign Up   View a printable version of the current page.

Added by Greg Wilkins , last edited by Greg Arakelian on Apr 04, 2008  (view change)
Labels: 
(None)

Contact the core Jetty developers at www.webtide.com
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

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.

mod_proxy

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:
    LoadModule proxy_module modules/mod_proxy.so

    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:
    ProxyRequests Off
    
    <Proxy *>
    Order deny,allow
    Allow from all
    </Proxy>
  4. Reverse proxy paths must be configured with URL of the jetty server:
    ProxyPass /test http://localhost:8080/test
  5. Frequently apache documentation will instruct that ProxyPassReverse configuration be used so that apache can rewrite any URLs in headers etc. However, with Jetty and well written webapplications, it is far better to use the ProxyPreserveHost configuration, so that Jetty may generate the correct URLs and they do not need to be rewritten:
    ProxyPreserveHost On
  6. It is also very useful to turn on proxy status monitoring (see management below):
    ProxyStatus On

mod_proxy_balancer

With apache 2.2 mod_proxy is able to use the extension mod_proxy_balancer

Configuration

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.

# map to cluster
ProxyPass /test balancer://my_cluster/test stickysession=JSESSIONID nofailover=On
ProxyPass /demo balancer://my_cluster/demo stickysession=JSESSIONID nofailover=On

# define the balancer, with http and/ or ajp connections
<Proxy balancer://my_cluster>
    BalancerMember ajp://yourjettyhost1:8009
    BalancerMember ajp://yourjettyhost2:8009
</Proxy>

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.

Management

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:

<Location /balancer>
SetHandler balancer-manager

Order Deny,Allow
Deny from all
Allow from all
</Location>


ProxyStatus On
<Location /status>
SetHandler server-status

Order Deny,Allow
Deny from all
Allow from all
</Location>

These UIs should be protected from external access.

Contact the core Jetty developers at www.webtide.com
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
Site running on a free Atlassian Confluence Open Source Project License granted to The Codehaus. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.6.2 Build:#919 Nov 26, 2007) - Bug/feature request - Contact Administrators