在nginx中为什么要尽量避免使用regex location

这是nginx的作者Igor在邮件列表中的回答:

A:I'm wondering about the regex usage in location though - this is one of
the things I like very much about nginx. Can you please elaborate the reasons for avoiding them?


Q:The difference is how nginx processes location.

If you use only prefix or exact locations, then nginx looks up
the longest match nevertheless of order of locations in configuration file.
This allows you to have hundreds or thousands locations without worrying
how a new location will affect the existant configuration.

Regex locations depend on order, so during adding a new location
you have to look though whole configuration to see if the new location
will affect it.

A man thinks usually that he creates a small configuration with regexes
and it will work always fine. But configuration usually grows eventually
and at some point it become a difficult task to add new locations.

Rewrite rules aggravate this more.

你可能感兴趣的:(location)