Search code examples
http-redirectsubdomaintomcat6mod-proxyapache2.2

Mapping a subdomain to a Servlet context using Apache 2.x and Tomcat 6.x


I have installed Archiva on my machine under Tomcat 6.x at http://dev.mycompany.com:8080/archiva and can access the application and everything, but I want to access it from the subdomain archiva.mycompany.com.

I have Apache 2.x running on port 80 and using Virtual Hosts and mod_proxy to route from other subdomains to the other various services I am running on this machine.

I now want to create a subdomain archiva.dev.mycompany.com and point that to dev.mycompany.com:8080/archiva.

I can't figure out what I need to put in my ProxyPass and ProxyPassReverse to make this work like I want it to.

I tried the following and all it does is add /archiva to the URL over and over again.

<VirtualHost *:80>
    ServerAdmin me@mycompany.com
    ServerName archiva.dev.mycompany.com
    ProxyPreserveHost On

    <Proxy *>
      Order allow,deny
      Allow from all
    </Proxy>
    ProxyPass / http://dev.mycompany.com:8080/archiva
    ProxyPassReverse / http://dev.mycompany.com:8080/archiva
</VirtualHost>

and I get this error message

HTTP Status 404 - /archivaarchiva/
type Status report
message /archivaarchiva/  
description The requested resource (/archivaarchiva/) is not available.

I went and dug through everything I could find on Google once again and tried the following:

ProxyPass / ajp://dev.mycompany.com:8080/archiva/
ProxyPassReverse / http://dev.mycompany.com:8080/archiva/

now I just get a 404 error code from the Winstone Servlet Engine, I know I am getting close.

Can anyone tell me what magic incantation I need to make this behave as I desire?


Solution

  • I had the exact same problem.

    What has to be done :

    • reconfigure archiva to have archiva running on / instead of /archiva/

    • configure reverse proxy in the apache2 configuration.

    So now i have "http://repo.[domain]/" for main archiva URL, pointing on "http://[domain]:[port]/"

    Here's my current Apache2 configuration :

    ProxyRequests Off
    ProxyPreserveHost On
    <VirtualHost [ip]>
    
            ServerName repo.[domain]
            ProxyPass / http://[ip]:8082/
            ProxyPassReverse / http://[ip]:8082/
    
            <Proxy *>
                  Order deny,allow
                  Allow from all
            </Proxy>
    
    </VirtualHost>
    

    And about the conf/jetty.xml configuration :

    -remove this :

    <!--
      <Call class="org.mortbay.jetty.webapp.WebAppContext" name="addWebApplications">
        <Arg><Ref id="Contexts"/></Arg>
        <Arg>./apps</Arg>
        <Arg>org/mortbay/jetty/webapp/webdefault.xml</Arg>
        <Arg><Ref id="plusConfig"/></Arg>
        <Arg type="boolean">True</Arg>
        <Arg type="boolean">False</Arg>
      </Call>
    -->
    

    +add this instead:

      <New class="org.mortbay.jetty.webapp.WebAppContext">
        <Arg><Ref id="Contexts"/></Arg>
        <Arg>./apps/archiva</Arg>
        <Arg>/</Arg>
        <Set name="configurationClasses"><Ref id="plusConfig"/></Set>
      </New>