SECTION: 200-General TITLE: apache QUESTION: Can Jetty be run with Apache? Firstly remember that Jetty is a HTTP/1.1 server and there is no need to use another webserver just to serve static content. However, if existing applications or special features require Apache to be used, it is possible to use Jetty behind Apache.
The setup uses the Apache transparent proxy feature. If you have an Apache server with DSO support or mod_proxy is already configured in, you may not have to rebuild Apache. You may also wish to use Apache's mod_rewrite. Some Apache installations in RedHat RPM format have everything you will need, right out of the box. These instructions presume that you have an Apache with the appropriate modules compiled in or available as DSO's for dynamic loading.
Configuring Jetty
Jetty's configuration need not change for this setup. Just use a different port than Apache.
Enabling Apache Dynamic Modules
If the modules you need are compiled in, omit this step. To enable the DSO versions of the modules, you will need to enable them with lines in your configuration file (httpd.conf) such as:
AddModule mod_rewrite.c # Optional
AddModule mod_proxy.c
Using Apache's Transparent Proxying
LoadModule rewrite_module modules/mod_rewrite.so # Optional
LoadModule proxy_module modules/libproxy.so
Apache's transparent proxy facility enables it to delegate HTTP requests to another web server such as Jetty. The simplest configuration gives Jetty all requests for certain parts of your site, for example all URLs starting with /foo/ or /bar/. If these parts of your site do not contain a lot of heavily-accessed static content such as images and other files, this is fine. You will not require mod_rewrite for this configuration. Just put one or more lines in your Apache config file such as:
In this example, Apache will delegate responsibility for all pages in the
/foo/ area of your site to Jetty on port 8080. In case some of the pages served by Jetty do redirects, it is probably wise to add an additional line:
ProxyPass /foo/ http://localhost:8080/foo/
Jetty could be running on a different machine, in which case substitute the name of that machine for "localhost" in both the lines above. You can use as many ProxyPass directives as needed. The one ProxyPassReverse line will fix up all redirect requests from Jetty to point to Apache, so your Jetty server won't become visible to visitors to your site.
ProxyPassReverse / http://localhost:8080/
You will not need mod_rewrite for this type of setup.
Transparent Proxying with mod_rewrite
If pages to be served by Jetty and by Apache are heavily intermixed, you can use mod_rewrite for finer control over Apache's decision whether to delegate the request to Jetty.
[[To be written.]]
Jetty with Apache with SSL
If your Apache server supports SSL, the transparent proxy feature will automatically handle SSL. It converts SSL requests to ordinary HTTP requests and encrypts the responses for you.
Performance Pros and Cons
If you prefer to use Apache to serve some of your content, or if you are constrained for any reason to using Apache, you can run Jetty just for the content you prefer to serve with Jetty. If you simply wish to optimize performance, you may need to experiment to find the best approach. Apache is probably faster than Jetty for static content, but routing requests through Apache slows them down somewhat also. Apache's transparent proxy feature claims only HTTP 1.0 compliance, so serving content directly with Jetty may reduce the number of TCP connections that must be established with the web browser.
We would love to learn of your results with performance testing.
Limitations
The Servlet API calls ServletRequest.getRemoteHost() and ServletRequest.getRemoteAddr() will refer to the host running Apache instead of the IP address of the remote user (or their proxy server). This limitation could be worked around in the future.
You may also wish to turn off Jetty's HTTP request logging. The limitation on access to remote addresses applies to Jetty logging also.