Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Configure Apache2, Jetty 7.1.6 Virtualhosts (each port one app)

Thanks for the write up!

and its nice to know that after 15 years jetty is still an overnight success :)


jesse mcconnell

On Fri, Oct 8, 2010 at 09:49, Christopher Armstrong <chstrong@xxxxxxxxx> wrote:
This is no question, it's how i managed to get Jetty running on Debian with one app each port and with Apache forwarding requests. Maybe it's useful for someone.

As beginner with Java and Jetty I had my struggles to find
sufficient information. Especially because Jetty is brand new
and there are no books yet on the market. As the Eclipse people
are very helpful on their mailinglist (also with beginners) I
thought I give back a "practical" manual for people trying to
do the same like me. Getting Jetty to work on Linux in a
Virtualhost environment using Apache to Proxy requests to
applications running on a seperate port each website.

This documentation is not sought as detailed explanation. It
should rather be a practical manual get you up and running.


      - -               - Jetty
User -                - Apache (80) -
      - -               - Jetty

Installation of the Java Runtime Environment
Over Debian Ports:
apt-get install <java version>

* Download the latest Java Runtime Environment for Linux
* Install it to /usr/local or to the path of your desire

I took the JRE from Debian ports, as it was easier to install.

Edit /etc/profile:
export PATH=$PATH:/usr/lib/jvm/java-6-sun-
export JAVA_HOME="/usr/lib/jvm/java-6-sun-"

Maybe you also want to add the path to /root/.bashrc or to your
user account in /home/<user>/.bashrc:

Download and install Jetty Hightide
Download Jetty:
Download the newest version of Jetty from:

Copy Jetty to /usr/local and register the rc script:
tar -xvzf jetty-distribution-<version>.v<build>.tar.gz
mv jetty-distribution-<version>.v<build> /usr/local/jetty
cd /etc/init.d/
ln -s /usr/local/jetty/bin/ jetty
update-rc.d jetty defaults
If you start jetty you should be able to connect to port 8080 out
of the box:
/etc/init.d/jetty start
Create custom directory structure
I have decided to use a seperate directory structure for the
jetty configuration:
A custom etc2 directory (used for jetty configuration):
mkdir /usr/local/jetty/etc2
A custom context directory (used for virtualhost configuration):
mkdir /usr/local/jetty/contexts2
A custom webapp directory (used for application repository):
mkdir /usr/local/jetty/webapps2
Configure in Jetty
File: /usr/local/jetty/etc2/
Configure id: jetty8090 (has to be a unique name for each server
              that is started)
Set name=port: each server must bind to a different port
Set name=configurationDir: Path to context relative to the
                           JETTY_HOME directory (/usr/local/jetty)
<!-- BEGIN OF FILE /usr/local/jetty/etc2/ -->
<Configure id="jetty8090" class="org.eclipse.jetty.server.Server">
    <Set name="connectors">
      <Array type="org.eclipse.jetty.server.Connector">
          <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
            <Set name="Host"></Set>
            <Set name="port">8090</Set>
            <Set name="maxIdleTime">30000</Set>
            <Set name="Acceptors">10</Set>
    <Set name="handler">
      <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
        <Set name="handlers">
         <Array type="org.eclipse.jetty.server.Handler">
             <New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
             <New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
    <Call name="addLifeCycle">
        <New class="org.eclipse.jetty.deploy.ContextDeployer">
          <Set name="contexts"><Ref id="Contexts"/></Set>
          <Set name="configurationDir"><SystemProperty name="jetty.home" default="."/>/contexts2/</Set>
          <Set name="scanInterval">5</Set>
<!-- END OF FILE /usr/local/jetty/etc2/ -->
File: /usr/local/context2/
Create directory: mkdir /usr/local/jetty/contexts2/
set name=contextPath: The root directory of your application url
Set name=war: Path to the webapps2 directory
Item: IP addresses or Hostnames
<!-- BEGIN OF FILE /usr/local/jetty/contexts2/ -->
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
  <Set name="contextPath">/</Set>
  <Set name="war"><SystemProperty name="jetty.home"/>/webapps2/</Set>
  <Set name="virtualHosts">
    <Array type="java.lang.String">
<!-- END OF FILE /usr/local/jetty/contexts2/ -->
Copy your application in to /usr/local/jetty/webapps2/
Add the config file to /usr/local/etc/jetty.conf
In order to start your new application on port 8090 add the file in
/usr/local/jetty/etc2 to jetty.conf:
Restart Jetty
After a restart of Jetty you can test your setup by connecting on to the
If you see your app you can proceed adding a second app that runs for
example on port 8091 by reusing the steps above.
Configuring Apache
To configure Apache the mod_proxy module has to be loaded:
cd /etc/apache2/mods-enabled/
ln -s ../mods-available/proxy.load .
ln -s ../mods-available/proxy_connect.load .
ln -s ../mods-available/proxy_balancer.load .
ln -s ../mods-available/proxy_http.load .
ln -s ../mods-available/proxy_ftp.load .
Now you can configure your VirtualHost:
File: /etc/apache2/sites-available/
<VirtualHost *:80>
  ErrorLog /var/log/apache2/
  CustomLog /var/log/apache2/www.app1.acc.log combined
  ProxyRequests Off
  ProxyVia Off
  ProxyPreserveHost On
  <Proxy *>
    AddDefaultCharset off
    Order deny,allow
    Allow from all
  ProxyStatus On
  <Location /status>
    SetHandler server-status
    Order Deny,Allow
    Allow from all
  ProxyPass /
  SetEnv proxy-nokeepalive 1
After a restart of Apache you should be able to connect to your url:

jetty-users mailing list

Back to the top