I've asked this question in a few places and I've found no answer. It should be pretty simple and a pretty common problem. Unfortunately I know nothing about tomcat and mod_proxy so I'm unable to figure it out.

I have a few apps running in tomcat, installed as wars and I can access them at myserver.com:8080/myapp

I simply want to create an apache vhost that forwards myapp.myserver.com to this myserver.com:8080/myapp using mod_proxy.

Hudson is a perfect example, there's no extra config, just a deployed war. So I set up the following apache vhost:

<VirtualHost *:80>
  ServerName hudson.myserver.ca

  ProxyPreserveHost On
  ProxyPass / http://localhost:8080/hudson
  ProxyPassReverse / http://localhost:8080/hudson

</VirtualHost>

and my proxy.conf is:

<IfModule mod_proxy.c>
  ProxyRequests Off

  <Proxy *>
    AddDefaultCharset off
    Order deny,allow
    Allow from all
  </Proxy>

  # Enable/disable the handling of HTTP/1.1 "Via:" headers.
  # ("Full" adds the server version; "Block" removes all outgoing Via: headers)
  # Set to one of: Off | On | Full | Block

  ProxyVia On
</IfModule>

Every request on every app has the same behavior. I go to hudson.myserver.ca for example, and it for some reason forwards on to hudson.myserver.ca/hudson, which gives a tomcat 404 that says

The requested resource (/hudsonhudson/) is not available.

happens for hudson, jira, confluence, and any other app.

What's with the extra 'hudson' and why isn't this working?


Solution 1:

Your proxy configuration should read:

ProxyPass / http://localhost:8080/hudson/
ProxyPassReverse / http://localhost:8080/hudson/

Then, you need to find out what is causing the 302 redirect in the first instance. There might be a rewrite rule somewhere else that is causing it.

On another note, you may want to consider using mod_proxy_ajp instead for Tomcat connections simply because that is what it was made for.