Expires directive and try_files rewrites not working

Hi, I am trying to use the try_files directive for rewrites together
with the Expires directive but when I do file extensions which are
included by the expires directive are ignored by my try_files directive,
it seems like they are served directly…

Here is an example config; http://pastebin.com/m4c4819a0
Note that files named .js are included in the expires directive and that
URL’s that have “phpAdsNew” in them should get rewritten to “openxads”,
example URL; http://www.techspot.com/phpAdsNew/adx.js (it returns 404
with the pastebinned config)

Is this by design or am I just doing it wrong?
I am running nginx stable v0.7.63 on RHEL v5.4 together with php-fpm all
from the Russian repository centos.alt.ru

Posted at Nginx Forum:

Hi Dounin, thanks for the link
I have actually read it more than once before but it helps when someone
puts it in context for you!

So in other words my first location;
location ~* .(jpg|jpeg|gif|css|png|ico|js)$ {
expires 7d;
}

It will serve all files with that file extension and then no other
matches or locations will be used, I’ve got that right?
In that case I guess we will have a little difficulty implementing the
expires directive for our site
Is there some other way we could implement it and still do the rewrites?

Posted at Nginx Forum:

Hello!

On Wed, Dec 02, 2009 at 01:22:01PM -0500, Per Hansson wrote:

Hi, I am trying to use the try_files directive for rewrites together with the Expires directive but when I do file extensions which are included by the expires directive are ignored by my try_files directive, it seems like they are served directly…

Here is an example config; http://pastebin.com/m4c4819a0
Note that files named .js are included in the expires directive and that URL’s that have “phpAdsNew” in them should get rewritten to “openxads”, example URL; http://www.techspot.com/phpAdsNew/adx.js (it returns 404 with the pastebinned config)

Is this by design or am I just doing it wrong?

http://wiki.nginx.org/NginxHttpCoreModule#location

In short: only one location matches particular query, and only
one configuration will be used. Don’t expect any merging magic.

Maxim D.