Mapping a subdomain to a Servlet context using Apa

2019-04-11 11:35发布

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?

2条回答
成全新的幸福
2楼-- · 2019-04-11 12:09

The reason you are getting:

HTTP Status 404 - /archivaarchiva/

is because you didn't end your ProxyPass last path with a / but you did ended the first path with one.

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

both ProxyPass and ProxyPassReverse should end with /

Rewrite to (taking note of the ending /):

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

see: http:// httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypass

If the first argument ends with a trailing /, the second argument should also end with a trailing / and vice versa. Otherwise the resulting requests to the backend may miss some needed slashes and do not deliver the expected results.

查看更多
我想做一个坏孩纸
3楼-- · 2019-04-11 12:21

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>
查看更多
登录 后发表回答