Running Apache and Tomcat together on different subdomains?

7,115

Solution 1

Try:

VirtualHost 'app.example.com:80'

instead of

VirtualHost '*:80'

Solution 2

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/
    
Share:
7,115

Related videos on Youtube

Ritesh M Nayak
Author by

Ritesh M Nayak

Thoughtworker living in Bangalore, India. Interested in Information Retrieval, Distributed Systems and ICT4D. Love music and code. My Website !!! I even got myself a cool stackoverflow careers resume. You can check that out here : My resume on Stackoverflow Careers

Updated on September 17, 2022

Comments

  • Ritesh M Nayak
    Ritesh M Nayak almost 2 years

    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?

    • theTuxRacer
      theTuxRacer over 13 years
      well, first of all you should post a link to the original question, so we can answer it there, or maybe at both places. Second, May I suggest a hack? In the <DocumentRoot> of app.example.com, give the webapp directory of tomcat6, ie /usr/share/tomcat6/webapps. PS: mod_proxy is useful for addresses like example.com/app which you can forward to internal ports.
    • theTuxRacer
      theTuxRacer over 13 years
      PS: I know its frustrating because I was trying to do the same. In the end, I kept port 8080 open, and directly goto www.example.com:8080 to the tomcat's webapp.
    • theTuxRacer
      theTuxRacer over 13 years
      I found this page for you, although is for CentOS, will work for any tomcat6+apache2 install. JUst make sure your proxy.conf file is in ../apache/mods-enabled/ folder. Link: library.linode.com/web-servers/apache/proxy-configuration/…