nginx parse var in if file exist statement error?

Valentin V. Bartenev i at vbart.ru
Wed Nov 2 13:34:44 UTC 2011


On Wednesday 02 November 2011 14:09:59 est wrote:
[...]
> So I have dir to store images, either jpg or png, the file name (image
> id) is unique. I want the URL to provide image id only, nginx to serve
> static jpg or png.
> 
> the config snippet is something like this:
> 
> 
> server {
>   listen 80;
>   error_log /var/log/nginx/error_imglib.log debug;
>   root /home/develop/image_library;
> 
>   location ~* ^/img/small/(\d+)/?$ {
>     set $fext 'jpg';
>     if (!-f '/home/develop/image_library/dump/$1-s.jpg'){
>       set $fext png;
>     }
>     alias '/home/develop/image_library/dump/$1-s.$fext' ;
>   }
> }
> 
[...]

server {
  listen 80;
  error_log /var/log/nginx/error_imglib.log debug;
  root /home/develop/image_library;

  location ~* ^/img/small/(\d+)/?$ {
    try_files /dump/$1-s.jpg /dump/$1-s.png =404
  }
}

wbr, Valentin V. Bartenev



More information about the nginx mailing list