1

If I needed to add a location rule specific to the .png files, I would normally use:

location ~* \.png$ {
    # …
}

An answer to this question has a highly upvoted comment that says:

If this occurs often (like thousands), it will incur a performance penalty due to regex matching. (…) I personally want Nginx "location" to support multiple "=" conditions instead of relying on a regex rule.

Is there a way to target a specific file extension (or multiple extensions) while avoiding regular expressions? If no, can I optimise the above regex further? (E.g. by making it more specific to a folder, maybe?)

mehov
  • 568
  • 1
  • 5
  • 14
  • If the files are in a specific folder and that folder is specified at the beginning of the URI, then the best approach is to use a prefix location. – Richard Smith Mar 24 '21 at 09:30
  • @mehov That is exactly what suggest the primary nginx developer Igor Sysoev (this [video](https://www.youtube.com/watch?v=jf3wIN-FwW4&t=1266s) is in Russian language, but the slides you can see are meaningful enough). I think nginx is badly missing some kind of suffix location feature (which can make possible to define PHP handler without invoking the PCRE library). However I think your question is related to [this](https://serverfault.com/questions/1058098/a-location-for-static-content-without-listing-every-possible-extension) one and can be considered as answered. – Ivan Shatsky May 13 '22 at 01:19

0 Answers0