In my answer to nginx location deny by file extension syntax, I've contemplated that the two separate regular expressions — one consisting of a bunch of filename extensions terminated by $
, and another one being a filename path like /\.
— might be faster as two separate location
s than a joined one with the help of the choice |
metacharacter.
What's faster with nginx
when ngx_regex.c
is using the pcre
library for regular expressions?
The two expressions run apart:
location \.(7z|bak|bz2|gz|rar|tar|zip)$ {return 403;}
location /\. {return 403;}
Or the one where the above are joined together with |
:
location \.(7z|bak|bz2|gz|rar|tar|zip)$|/\. {return 403;}
Let's have an optimistic view towards people trying to break in versus legitimate site visitors — assume that most input paths would not match either of the expressions above.
Which choice would result in a faster no-match?
Are there any end-of-line optimisations that are possible with the first expression that would not take place in the combined one?