tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Warnier ...@ice-sa.com>
Subject Re: static content not served for non-root apps via mod_jk
Date Sat, 14 Jan 2012 14:29:51 GMT
Eric P wrote:
> I remember now why static content works for my ROOT app.  I have
> Apache aliases set-up pointing to specific system directories for all
> static content.
> 
> For example, I have all images for the ROOT app aliased here.
> Alias /img /opt/tomcat7/webapps/ROOT/img
> <Directory "/opt/tomcat7/webapps/ROOT/img">
>     Options Indexes MultiViews
>     AllowOverride None
>     Order allow,deny
>     Allow from all
> </Directory>
> 
> But is there a better approach for this so that I don't have to create
> static content aliases for each new Tomcat app I deploy?  I would be
> stuck using a unique alias for every app which seems crazy.
> 
> Thanks,
> Eric
> 
> 2012/1/13 Eric P <eric.maillist@gmail.com>:
>> Hi all,
>>
>> I'm having trouble getting Apache to serve static content (jpg, css, js, etc.) for
Tomcat apps via mod_jk for any
>> application except the ROOT Tomcat app.  The ROOT app shows static content just fine.
>>
>> I have the following Apache settings attempting to point *all* requests to Tomcat
and unsetting certain static content
>> extensions so that Apache will serve them.
>>
>> ...clip...
>> # Send everything to Tomcat
>> JkMount /* ajp13
>>
>> # And then unsend static content so that httpd will serve it
>> JkUnMount /*.js ajp13
>> JkUnMount /*.css ajp13
>> JkUnMount /*.jpg ajp13
>> JkUnMount /*.png ajp13
>> JkUnMount /*.gif ajp13
>> ...clip...
>>
>> These settings work for the ROOT Tomcat app but not for anything else including Tomcat's
manager app.
>>
>> FYI. when I access via Tomcat's port/web server everything works.
>> E.g., http://localhost:8080/manager/html
>>
>> But not when I access via port 80.
>> E.g., http://localhost/manager/html
>>
>> I"m seeing a 404 Not Found for all static content via port 80/Apache (again, the
only exception is any static content
>> belonging to the ROOT Tomcat app).  I'm experiencing the exact same behavior on both
an Ubuntu and CentOS.
>>

1) Not a direct answer, but you may want to have a look at this alternative way to set up

mod_jk proxying in Apache httpd :
http://tomcat.apache.org/connectors-doc/reference/apache.html
at the very bottom of the page, the section :
Using SetHandler and Environment Variables

If you are familiar with the Apache httpd configuration style, this may be somewhat easier

than the JkMount/JkUnMount syntax.
(I personally prefer this alternative because I find that it fits better with the usual 
Apache configuration style, it allows me to use <Location> and <LocationMatch>,
and it 
allows me to use other Apache directives (e.g. authentication-related) within such sections.)

2) This being said and joining another comment : if you are proxying everything else to 
Tomcat anyway, you may want to simplify your life and use Tomcat directly as the webserver

for everything (including static content).  Tomcat is just as fast for that as Apache, and

you save yourself the overhead of Apache httpd and mod_jk; but mainly you would be 
simplifying your configuration.

3) In your explanation above, you mention JkMount and JkUnMount, but you are not saying 
where these instructions appear.  If you are using Apache VirtualHosts, you may want to 
check that your Jk(Un)Mount instructions are properly "transferred" between the main host

and the virtual ones.  Look up "JkMountCopy".

4) About aliasing : aliasing your Tomcat webapp directories in Apache (thus allowing 
Apache direct access to them) is a bad idea : by doing this, you completely circumvent 
whatever security may be implemented in Tomcat.
See the note at the very beginning of the same page
http://tomcat.apache.org/connectors-doc/reference/apache.html

(It is also not portable of course if you ever move that Tomcat - but not Apache - to 
another host).

5) You may also want to replace some lines as follows :

Old:
 >> # Send everything to Tomcat
 >> JkMount /* ajp13
 >>
 >> # And then unsend static content so that httpd will serve it
 >> JkUnMount /*.js ajp13
 >> JkUnMount /*.css ajp13
 >> JkUnMount /*.jpg ajp13
 >> JkUnMount /*.png ajp13
 >> JkUnMount /*.gif ajp13

New:
 >> # Send everything to Tomcat
 >> JkMount /* ajp13
 >>
 >> # And then unsend static content so that httpd will serve it
 >> JkUnMount /*.js ajp13   <-- for the ROOT webapp
 >> JkUnMount /*/*.js ajp13 <-- for the other webapps
 >> JkUnMount /*.css ajp13
 >> JkUnMount /*/*.css ajp13
etc..



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message