Running Apache and Tomcat together on different subdomains?

Posted this on ServerFault but didn't get a response. Hoping I will have better luck on the Ubuntu site.

I have been trying to get this working the whole of today. I have a server which resolves to the domain example.com . This is running Apache2 and Tomcat 6. The requirement is to direct requests to example.com to apache2 and app.example.com to Tomcat. I know I have to do a VirtualHost proxy pass for this to work. Here are the settings on my server.

/etc/hosts file looks something like this

127.0.0.1     localhost localhost.localdomain example.com app.example.com 

I have two virtual host files for the different domains in /etc/apache2/sites-enabled

/etc/apache2/sites-enabled/example.com looks like this

<VirtualHost *:80>

  # Admin email, Server Name (domain name) and any aliases
  ServerAdmin webmaster@localhost
  ServerName  example.com
  ServerAlias www.example.com

  DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog /var/log/apache2/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>


</VirtualHost>

/etc/apache2/sites-enabled/app.example.com file looks like this

<VirtualHost *:80>
  ServerName  app.example.com
  ServerAlias www.app.example.com

  ProxyPreserveHost On
  ProxyPass / http://localhost:8080/
  ProxyPassReverse / http://localhost:8080/
  SetEnv force-proxy-request-1.0 1
  SetEnv proxy-nokeepalive 1
</VirtualHost>

mod_proxy and mod_rewrite are both enabled on the apache instance. I have a CNAME entry for both example.com and app.example.com. When accessing app.example.com, I get an 403 forbidden, saying I have no access to / on the server. What am I doing wrong?


I have similiar problem when I use such construction in virtual host definition:

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

In my case it start working when I point application:

  • these allow you to redirect such address: http://app.example.com/confluence

    ProxyPass /confluence/ http://localhost:8180/confluence/ 
    ProxyPassReverse /confluence/ http://localhost:8180/confluence/
    
  • these allow you to redirect such address: http://app.example.com to proper application

    ProxyPass / http://localhost:8180/confluence/ 
    ProxyPass / http://localhost:8180/confluence/
    

Try:

VirtualHost 'app.example.com:80'

instead of

VirtualHost '*:80'