简体   繁体   中英

Mod_JK, Tomcat & Apache Httpd “File not found” when using Alias

I've been trying to find a solution to what I think should be a very common use of Alias with Tomcat & Apache Httpd but I can't find it.

I have Tomcat running my application server and I want to be able to use aliases to serve dynamic content. I configured Apache Httpd as the front end with Mod_JK to serve all dynamic files via Tomcat. This works fine except when using aliases as Tomcat doesn't know how to handle the Alias.

Basically I have my Tomcat application /webapps/myApp inside that I have "/folderA" so using http:localhost:8080/myApp/folderA works fine as well as localhost/myApp/folderA. I want to be able to user /folderB to point to /folderA and serve dynamic content and that's when things fail.

I have everything working well with mod_jk and the alias requests get redirected to Tomcat, however Tomcat does not know what to do with the alias so it tries to find /webapps/myApp/folderB which doesn't exists so I get a "file not found" error.

I tried using a <Context path... but then I get served static content. I also tried using Apache RewriteRule to pass requests from /folderB to /folderA but that doesn't work either. Below is an example of the VirtualHost settings I have. I'm guessing I need to do something in Tomcat's end so that it knows how to handle /folderB and point it to /folderA OR to make httpd translate /folderB to /folderA before passing the info to Tomcat.

Any help is appreciated. Thanks!

<VirtualHost *:80>


    DocumentRoot "/webapps/ROOT"
    Alias /folderB "webapps/ROOT/folderA"


    JkMount /folderB/* myWorker

    ServerName myServer.local
    ServerAlias www.myServer.local

    ErrorLog "logs/myServer.local-error.log"
</VirtualHost>

Really late, but I have the same problem and here is a working solution: The Alias within the VirtualHost is ignored for all files handled by the mod_jk .

Update your tomcat/conf/server.xml and add a Context to your Host:

  <Host name="your-domain.com" appBase="webapps">
    <!-- root path -->
    <Context path="" docBase="/your/app/" />
    <!-- alias for folderB -->
    <Context path="/folderB" docBase="/your/app/somewhere/else/folderb/" /> 
  </Host>

This really confuses me, because ColdFusion and the Connector know the Apache Aliases. I will update my answer if I have any progress..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM