help with location tag / reg ex

Valentin V. Bartenev ne at vbart.ru
Thu Dec 29 19:22:37 UTC 2011


On Thursday 29 December 2011 22:51:13 Ilan Berkner wrote:
> I'd like to match all of the media files in this sub directory (and
> subsequent directories) but its not working.
> 
>     location ~* /_games/\.(jpg|jpeg|png|gif|swf|flv|mp3)$ {
>       expires max;
>     }
> 
> My regular expression is off the mark...
> 

Your regexp matches URIs only like these:
/_games/.gif
/_games/.flv
etc...

Probably, you want:

  location ~* /_games/.+\.(?:jpe?g|png|gif|swf|flv|mp3)$ {
      expires max;
  }

or, maybe:

  location /_games/ {
      location ~* \.(?:jpe?g|png|gif|swf|flv|mp3)$ {
         expires max;
      }
  }

Please, read:
 man pcrepattern
 man pcresyntax


wbr, Valentin V. Bartenev



More information about the nginx mailing list