nginx and tomcat integrated but how to serve static files

Irfan Khan irfan.khan at enovatemedia.co.in
Mon Dec 10 16:25:01 UTC 2012


Hi,

Thanks for the suggestion, but unfortunately it didn't worked. I have tried
to create new location to be served by nginx but all requests goes to tomcat
by next location  directive. Any html within /foo/ directory doesn't work at
all.
I am a newbie to Nginx and really loves it. I hope some regex combination
would help to solve the problem.

Please suggestion!

My config as follows;

Location /foo/*
Root /tomcat/webapps/abc/
Index.html

> location /abc/ {

proxy_pass http://localhost:8080;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header 
X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host 
$http_host;
 
 }







Irfan Khan
Lead - IT

eNovate Media Solutions Pvt Ltd
#204, 2nd Floor, Cunningham Classic
22, Cunningham Road
Bangalore - 560052
Voice - + 91 80 41657660 | Mob - +91 903 589 38 14
www.enovatemedia.com


-----Original Message-----
From: nginx-bounces at nginx.org [mailto:nginx-bounces at nginx.org] On Behalf Of
Francis Daly
Sent: 07 December 2012 21:31
To: nginx at nginx.org
Subject: Re: nginx and tomcat integrated but how to serve static files

On Fri, Dec 07, 2012 at 04:38:20PM +0530, Irfan Khan wrote:

> There are some html static files and images in my application which I 
> don't to be served by tomcat. again, I am trying to as much as 
> performance boost for my app.
> 
> I am tried to do some research but unable to get solutions.

nginx chooses how to handle a request based on the location{} blocks you
have defined.

Currently, you have: if it starts with /abc/, proxy to tomcat; otherwise,
serve from the filesystem.

So: which urls do you really want proxied to tomcat, and which do you really
want served from the filesystem?

If I guess that "url starts with /abc/ and ends in html" means "serve from
filesystem, not tomcat", then you could add one line:

> location /abc/ {

    location ~ html$ {}

> proxy_pass http://localhost:8080;
> proxy_set_header X-Real-IP $remote_addr; proxy_set_header 
> X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host 
> $http_host;
> 
> }

and a request for /abc/a.html will look for the file
/usr/local/nginx/html/abc/a.html (or strictly: abc/a.html below whatever you
have configured "root" to be).

Best would be to make the non-tomcat things be in a different url prefix to
the tomcat things -- such as /abc/static, for example -- because then you
could just use prefix locations. That depends on how your application is
written, which may not be changeable.

	f
-- 
Francis Daly        francis at daoine.org

_______________________________________________
nginx mailing list
nginx at nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx



More information about the nginx mailing list