conditional "Expires" header config bug

ghazel at gmail.com ghazel at gmail.com
Wed Dec 8 05:39:39 MSK 2010


2010/12/7 Maxim Dounin <mdounin at mdounin.ru>:
>
> On Tue, Dec 07, 2010 at 01:43:16PM -0800, ghazel at gmail.com wrote:
>
>> On Tue, Dec 7, 2010 at 1:36 PM, Maxim Dounin <mdounin at mdounin.ru> wrote:
>> > On Tue, Dec 07, 2010 at 01:09:54PM -0800, ghazel at gmail.com wrote:
>> >>
>> >> I'm trying to conditionally set the "Expires" header. This tiny
>> >> snippet does not work as expected:
>> >>
>> >>     location ~* testing/.*\.png$ {
>> >>       if ($request_uri ~* "\.png\?[0-9]+$") {
>> >>         expires max;
>> >>       }
>> >>       try_files $uri /testing/oops.png;
>> >>     }
>> >>
>> >> The basic problem is that if the png does not exist and there is a
>> >> query string, I get a 404 instead of oops.png. All other combinations
>> >
>> > This is expected - try_files isn't inherited into implicit
>> > location created by "if".
>>
>> I would very much like some more examples of what you mean here. It's
>> not clear to me why IfIsEvil occurs, or how to think about what the if
>> statement is actually doing.
>
> What "if" statement (inside location) actually doing is creating
> implicit nested location (conditional one), with some hacks to
> make handler modules (proxy_pass, fastcgi_pass, ...) to be
> inherited into this location (normally they aren't).
>
> 2. Mentioned hacks are incomplete / broken and may cause various
> problems.  As in your case - they don't handle try_files (which
> isn't normally inherited, too).

It all makes so much sense now! If that explanation were on
http://wiki.nginx.org/IfIsEvil perhaps other people could benefit from
it. Also a list of inherited commands / handlers might be helpful.

I managed to get my config fully working to my satisfaction, with 6
locations sections and 3 teapot error code jumps (there was more than
I pasted here, obviously). Thanks again.

-Greg



More information about the nginx mailing list