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 :)

http://www.eclipse.org/jetty/about.php

cheers!
jesse

--
jesse mcconnell
jesse.mcconnell@xxxxxxxxx


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.
 
 
INSTALL APACHE2 & JETTY HIGHTIDE 7.1.6 ON DEBIAN WITH VIRTUALHOSTS
==================================================================

Foreword
------------------------------------------------------------------
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.

Overview
------------------------------------------------------------------

      - www.app1.com -               - Jetty 127.0.0.1:8090
User -                - Apache (80) -
      - www.app2.com -               - Jetty 127.0.0.1:8091

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

Manually:
* 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-1.6.0.20/bin
export JAVA_HOME="/usr/lib/jvm/java-6-sun-1.6.0.20"

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:
http://www.eclipse.org/jetty/

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.sh 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
lynx http://127.0.0.1:8080
 
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 www.app1.com in Jetty
-----------------------------------------------------------------
File: /usr/local/jetty/etc2/www.app1.com.xml
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/www.app1.com.xml -->
<Configure id="jetty8090" class="org.eclipse.jetty.server.Server">
    <Set name="connectors">
      <Array type="org.eclipse.jetty.server.Connector">
        <Item>
          <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
            <Set name="Host">127.0.0.1</Set>
            <Set name="port">8090</Set>
            <Set name="maxIdleTime">30000</Set>
            <Set name="Acceptors">10</Set>
          </New>
        </Item>
      </Array>
    </Set>
    <Set name="handler">
      <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
        <Set name="handlers">
         <Array type="org.eclipse.jetty.server.Handler">
           <Item>
             <New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
           </Item>
           <Item>
             <New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
           </Item>
         </Array>
        </Set>
      </New>
    </Set>
    <Call name="addLifeCycle">
      <Arg>
        <New class="org.eclipse.jetty.deploy.ContextDeployer">
          <Set name="contexts"><Ref id="Contexts"/></Set>
          <Set name="configurationDir"><SystemProperty name="jetty.home" default="."/>/contexts2/www.app1.com</Set>
          <Set name="scanInterval">5</Set>
        </New>
      </Arg>
    </Call>
</Configure>
<!-- END OF FILE /usr/local/jetty/etc2/www.app1.com.xml -->
File: /usr/local/context2/www.app1.com/www.app1.com.xml
Create directory: mkdir /usr/local/jetty/contexts2/www.app1.com
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/www.app1.com/www.app1.com.xml -->
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
  <Set name="contextPath">/</Set>
  <Set name="war"><SystemProperty name="jetty.home"/>/webapps2/www.app1.com.war</Set>
  <Set name="virtualHosts">
    <Array type="java.lang.String">
      <Item>www.app1.com</Item>
      <Item>app1.com</Item>
      <Item>127.0.0.1</Item>
    </Array>
  </Set>
</Configure>
<!-- END OF FILE /usr/local/jetty/contexts2/www.app1.com/www.app1.com.xml -->
 
Copy your application in to /usr/local/jetty/webapps2/www.app1.com.war
 
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:
--pre=etc2/www.app1.com.xml
#--pre=etc2/www.app2.com.xml
--pre=etc/jetty-logging.xml
 
Restart Jetty
-------------------------------------------------------------------------
After a restart of Jetty you can test your setup by connecting on to the
port:
lynx http://127.0.0.1:8090
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/www.app1.com.conf
<VirtualHost *:80>
  ServerName www.app1.com
  ServerAlias app1.com
  ErrorLog /var/log/apache2/www.app1.com.err.log
  CustomLog /var/log/apache2/www.app1.acc.log combined
  ProxyRequests Off
  ProxyVia Off
  ProxyPreserveHost On
  <Proxy *>
    AddDefaultCharset off
    Order deny,allow
    Allow from all
  </Proxy>
  ProxyStatus On
  <Location /status>
    SetHandler server-status
    Order Deny,Allow
    Allow from all
  </Location>
  ProxyPass / http://127.0.0.1:8090/
  SetEnv proxy-nokeepalive 1
</VirtualHost>
 
After a restart of Apache you should be able to connect to your url:
http://www.app1.com

_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-users



Back to the top