gpt4 book ai didi

Nginx 位置优先级

转载 作者:行者123 更新时间:2023-12-03 04:18:05 26 4
gpt4 key购买 nike

位置指令按什么顺序触发?

最佳答案

来自HTTP core module docs :

  1. 带有“=”前缀的指令与查询完全匹配。如果找到,搜索就会停止。
  2. 所有剩余的指令都带有常规字符串。如果此匹配使用“^~”前缀,则搜索停止。
  3. 正则表达式,按照它们在配置文件中定义的顺序排列。
  4. 如果 #3 产生匹配,则使用该结果。否则,将使用#2 中的匹配项。

文档中的示例:

location  = / {
# matches the query / only.
[ configuration A ]
}
location / {
# matches any query, since all queries begin with /, but regular
# expressions and any longer conventional blocks will be
# matched first.
[ configuration B ]
}
location /documents/ {
# matches any query beginning with /documents/ and continues searching,
# so regular expressions will be checked. This will be matched only if
# regular expressions don't find a match.
[ configuration C ]
}
location ^~ /images/ {
# matches any query beginning with /images/ and halts searching,
# so regular expressions will not be checked.
[ configuration D ]
}
location ~* \.(gif|jpg|jpeg)$ {
# matches any request ending in gif, jpg, or jpeg. However, all
# requests to the /images/ directory will be handled by
# Configuration D.
[ configuration E ]
}

如果仍然令人困惑,here's a longer explanation .

关于Nginx 位置优先级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5238377/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com