Welcome! Log In Create A New Profile

Advanced

Re: How to get a 404 logged with try_files?

May 03, 2011 08:46AM
On Mon, May 02, 2011 at 10:22:50AM -0400, monster wrote:
> Hi! Just started with Nginx after reading it reached 1.0.
> Congratulation!
>
> I'm trying to get my test site to return a "missing image" icon when an
> image is missing, but have a 404 logged so I know I messed up something.
> I want to specify the images name without file extensions, in case I
> move some from PNG to JPG, or the other way around. My problem is that
> try_files doc says last path MUST exist. I would like last path to be
> $uri and cause a 404, not a 500. Tried using error_page to convert 500
> to 404, but did not have any effect. Thanks for any advice!
>
> location ~ ^/img/[^\.]*$ {
> try_files $uri.png $uri.jpg $uri.gif $uri;
> error_page 500 =404 /img/missing;
> }
>
> location /img/ {
> error_page 404 /img/missing;
> }
>
> location = /img/missing {
> rewrite .* /img/icon/missing.png;
> }

location /img/ {
error_page 404 /img/icon/missing.png;

location ~ ^/img/[^\.]*$ {
try_files $uri.png $uri.jpg $uri.gif $uri =404;
}
}

location = /img/icon/missing.png {
# nothing
}


--
Igor Sysoev

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

How to get a 404 logged with try_files?

monster May 02, 2011 10:22AM

Re: How to get a 404 logged with try_files?

monster May 02, 2011 02:21PM

Re: How to get a 404 logged with try_files?

Igor Sysoev May 03, 2011 08:46AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 197
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready