0
votes

I have a web application project with very large media files and I would like them seperate from the rest of the application but remain in the same path.

So for example,if I have a file in the apache document root:

/var/www/html/myapp1/media/bigFile.wmv

but the rest of my app resides in the tomcat app directory:

/usr/share/tomcat/webapps/myapp1/

is there a way to see if Apache has the file and then if not look in Tomcat and then if nothing is found then give the 404?

I've tried doing this just now and got a tomcat 404. This is because my tomcat is running behind Apache and all requests are sent directly to tomcat.

Is there a way to see if Apache has the file, then if not found, look in Tomcat and then, if nothing is found again, then give the 404?

It would also be preferential is the opposite were true, if I could go from tomcat to apache to 404, I could just drop the entire application + media files in apache, then drop new versions of the app in tomcat. I wouldn't have to do a diff between the two directories.

Here is my current configuration file I use to redirect to tomcat:

<VirtualHost *:80>
   ServerName localhost
   ServerAlias website.com

   ProxyRequests Off
   ProxyPreserveHost On

   ErrorLog /var/log/httpd/tomcat.error.log
   CustomLog /var/log/httpd/tomcat.log combined

   <Proxy *>
           Order deny,allow
           Allow from all
   </Proxy>

   ProxyPass / http://localhost:8080/
   ProxyPassReverse / http://localhost:8080/
</VirtualHost>
1

1 Answers

1
votes

The best way to do this is with httpd deciding it can't fulfill the request, and then proxying to Tomcat as a fall-back. If Tomcat finds nothing, then Tomcat will issue the 404, rather than httpd somehow detecting that and re-taking control.

Like most crazy things, you ought to be able to do this with mod_rewrite:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule /path/to/apply - [H=jakarta-servlet]

Completely untested, but might just work (just like most mod_rewrite recipes)!