Domain forwarding
using DNS, Apache and Tomcat
the problem
You have a web application running on Tomcat. Now you obtained a nice domain name and you want to point it to your web application. Or let's make it more interesting: you have 2 web applications running on a single Tomcat instance, and you bought 2 domain names.
- http redirect
- domain forwarding, or "cloaking"
- edit dns records
http redirect
This method redirects a request for your domain name to the specified resource. The response will contain the location of the destination resource, and and indication if this redirecting is permanent or temporary (HTTP status codes 301 and 302).
Using this method you can redirect to any resource you want, for example to
domain forwarding ("cloaking")
Using domain forwarding, sometimes called "cloaked forwarding" or "cloaking", a request to your domain name is handled by your domain registrar's server, where it opens an autmatically generated web page that contains an (i)frame that loads your destination resource.
Using this method you can redirect to any resource you want, for example to
dns
By editing DNS records you can solve the problems of the above methods, but it comes with some difficulties itself.
The main difficulty is that in DNS A records, you can specify a destination IP address, but nothing else. No port number or web application name there. So how are you going to distinguish on your server between web app A and web app B, when requests coming from domain name A and domain name B arrive at that same IP address ?
The answer lies in using the HTTP "Host" header, that contains the domain name that initiated this HTTP request. When you set up everything correctly, the users will see in their browser's address bar things like
The rest of this page shows you how to set it up using Apache HTTP server and Tomcat. Many thanks to Jose Garcia who figured out (and implemented on this server) and documented the gory details of the configuration described below.
setting up dns forwarding with apache and tomcat
This description assumes you're doing the DNS trick using the domain name "geonetwork.tv". It assumes that your Tomcat is up and running a web application called "geonetworktv" on a Linux server.
installation
install Apache HTTP server:
configuration of mod_jk
Edit
configuration of Tomcat
If you changed the default ajp13 port, do it here too:
...
<Listener className="org.apache.jk.config.ApacheConfig"
modJk="/usr/lib/apache2/modules/mod_jk.so"
workersConfig="/etc/libapache2-mod-jk/workers.properties"/>
...
</server>
appBase="/home/pipo/apps/tomcat/apache-tomcat-6.0.18/geonetworktv"
unpackWARs="true"
autoDeploy="true"
xmlValidation="false"
xmlNamespaceAware="false">
<Context path="" docBase="ROOT" debug="0"/>
<Alias>www.geonetwork.tv<Alias/>
</Host>
</Host -->
configuration of Apache
The Apache default site configuration is in
ServerName geonetwork.tv
ServerAlias geonetwork.tv www.geonetwork.tv
JkMount /* ajp13_worker
<VirtualHost *:80>
ServerName anotherdomain.com
ServerAlias alias1.com alias2.com
JkMount /* ajp13_worker 2
<VirtualHost *:80>