Welcome! Log In Create A New Profile

Advanced

Re: conditional "Expires" header config bug

Anonymous User
December 07, 2010 04:46PM
On Tue, Dec 7, 2010 at 1:36 PM, Maxim Dounin <mdounin@mdounin.ru> wrote:
> On Tue, Dec 07, 2010 at 01:09:54PM -0800, ghazel@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.

>> seem to work fine. I have read IfIsEvil, but the alternatives
>> presented (try_files, return, redirect) do not cover the case of
>> setting headers.
>
> Not "redirect" but "rewrite ... last".  Anyway, they are cover the
> case in question.

Er yes, sorry.

> Generally safe parttern using only "return" looks like the
> following:
>
>    location ~ \.png$ {
>        recursive_error_pages on;
>        error_page 418 = @expires;
>
>        if ($args ~ "^[0-9]+$") {
>            return 418;
>        }
>
>        try_files $uri /testing/oops.png;
>    }
>
>    location @expires {
>        expires max;
>        try_files $uri /testing/oops.png;
>    }
>
>    location = /testing/oops.png {
>        # we don't want expires max on oops
>    }

This is clever! I didn't know you could set an internal location with
error_page. Not that it isn't documented, just that I never even
considered looking there for that sort of thing since the case I'm
using it for is not an error.

Thanks for your help!

-Greg

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

conditional "Expires" header config bug

Anonymous User December 07, 2010 04:14PM

Re: conditional "Expires" header config bug

Maxim Dounin December 07, 2010 04:40PM

Re: conditional "Expires" header config bug

Anonymous User December 07, 2010 04:46PM

Re: conditional "Expires" header config bug

Maxim Dounin December 07, 2010 06:26PM

Re: conditional "Expires" header config bug

Anonymous User December 07, 2010 09:42PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 114
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready