Domain – Mapping an external Domain on a Web Application (in Tomcat) via Apache2

apache-2.2domaintomcat

I know that there are possible duplicates on serverfault, but I read a lot (not only the last days) but I couldn't make it working 100%.

I have the domain http://jetwick.de bought via Strato and then I have a server with a static IP. I can configure the DNS settings for jetwick.de at Strato: the IP directly points to the IP of our server via A-Record. This works.

Now I want that my application which is available from tomcat under localhost:8080/jetwick is shown under jetwick.de – nothing more 🙂

I have the following apache config on our server /etc/apache2/vhosts/jetwick

<Virtualhost *:80>
      ServerName http://jetwick.de
      ServerAlias jetwick.de www.jetwick.de jetwick.com www.jetwick.com

      ProxyRequests Off
      ProxyPreserveHost On   

      ProxyPass / http://localhost:8080/jetwick/
      ProxyPassReverse / http://localhost:8080/jetwick/

</Virtualhost>

This partially works. But I have problems when I query:

  1. jsessionid should NOT be shown – only for clients which do not allow cookies. I guess the cookie info gets lost somewhere like the favicon …?
  2. an additional directory jetwick.de/jetwick will be shown (in the following request the jsessionid disappears)

How would you fix that? You can also point me to a site/duplicate where this case is described, of course!

Do I need mod_jk to make cookies properly working like the answer here suggests?

Update
The following settings solved the first (cookie) problem:

ProxyPassReverseCookiePath /jetwick /

Best Answer

Hmmm. Try migrating to a mod_proxy_ajp config first (assuming you have it included - it's a stock module with many modern Apache installs) to see if that does it. First, make sure your port 8009 AJP connector is uncommented in Tomcat's server.xml:

<Connector enableLookups="false" port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8" />

Then set up Apache pretty much the same; you might consider using a one-node pool so that you can have it "see" the jsessionid. Then add some rewrite rules to mask the directory name:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/jetwick/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /jetwick/$1

ProxyPass /jetwick/ balancer://local/ stickysession=JSESSIONID|jsessionid
<Proxy balancer://local>
  BalancerMember ajp://127.0.0.1:8009
</Proxy>

I don't have a Tomcat engine handy right now to test that, but it looks right when I read it... :) You might need a [PT] flag on the rewriterule, play with it and see what you get.