这是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.
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.
nginx作者Igor解释了使用正则表达式匹配在location配置中的弊端,包括配置文件的维护难度增加和重写规则带来的复杂性。建议使用前缀或精确匹配以简化配置。
363

被折叠的 条评论
为什么被折叠?



