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

荒凉一梦 提交于 2019-12-06 07:10:50

问题


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?


回答1:


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>



回答2:


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.



来源:https://stackoverflow.com/questions/4404770/mapping-a-subdomain-to-a-servlet-context-using-apache-2-x-and-tomcat-6-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!