Deploy to server machine

Preface

This document explains how to deploy your original acornsnap war file to server machine. This document assumes following situation.

Workflow (Main)

Download tomcat from http://tomcat.apache.org. And the install it.

# cd /opt
# wget http://ftp.kddilabs.jp/infosystems/apache/tomcat/tomcat-6/v6.0.29/bin/apache-tomcat-6.0.29.tar.gz
# tar xzf apache-tomcat-6.0.29.tar.gz && rm apache-tomcat-6.0.29.tar.gz
# chown -R tomcat:tomcat apache-tomcat-6.0.29
# su - tomcat
$ cd /opt/apache-tomcat-6.0.29

Clean pre-installed sample applications. And then add localhost directory. If you want to add another virtual host, add directory here.

$ rm -r webapps/*
$ mkdir webapps/a.com
$ mkdir webapps/b.net

Modify conf/server.xml to change applications base directory. If you want to add another virtual host, copy this Host element and modify appBase attribute.

<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1"
      redirectPort="8443" useBodyEncodingForURI="true" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8"/>

<!-- :(omitting..) -->

<Host appBase="webapps/a.com" autoDeploy="true" name="localhost" 
  unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">
<!-- :(omitting..) -->
</Host>
<Host appBase="webapps/b.net" autoDeploy="true" name="localhost" 
  unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">
</Host>

Modify conf/web.xml to change the server's runlevel.

<context-param>
  <param-name>runlevel</param-name>
  <param-value>test</param-value> <!-- or development,product -->
</context-param>

At the end, launch tomcat.

$ ./bin/startup.sh
$ exit

Place your war files to webapp/a.com or webapp/b.net directory. Tomcat will find and launch them automatically.

Workflow (Collaborating to Apache http server)

Modify /etc/httpd/conf.d/proxy_ajp.conf.

<VirtualHost *:80>
  ServerName a.com
  ProxyPass / ajp://a.com:8009/
  ProxyPassReverse / ajp://a.com:8009/
  <Proxy *>
    Order deny,allow
    Allow from all
  </Proxy>
</VirtualHost>

<VirtualHost *:80>
  ServerName b.net
  ProxyPass / ajp://b.net:8009/
  ProxyPassReverse / ajp://b.net:8009/
  <Proxy *>
    Order deny,allow
    Allow from all
  </Proxy>
</VirtualHost>

If you use SSL, add follwing to /etc/httpd/conf.d/ssl.conf. Sorry, I don't know how to setup multiple domains at same time.

<!-- :(omitting..) -->

ServerName a.com
ProxyPass / ajp://a.com:28009/
ProxyPassReverse / ajp://a.com:28009/
</VirtualHost>

Check new configuration and restart http server.

# service httpd configteset
# service httpd restart

If you want to show error page when tomcat is down(apache httpd throws 500 error), change settings in proxy_ajp.conf.

<VirtualHost *:80>
  ServerName a.com
  ProxyPass /errors !
  ProxyPass / ajp://a.com:8009/
  ProxyPassReverse / ajp://a.com:8009/
  <Proxy *>
    Order deny,allow
    Allow from all
  </Proxy>
  Alias /errors /path/to/docs
  ErrorDocument 500 /errors/500.html
</VirtualHost>
Managed by LumberMill, Inc.