nginx的location匹配逻辑(翻译自官网)
2016-01-22 15:52
597 查看
A regular expression is preceded with the tilde (
for case-sensitive matching, or the tilde-asterisk (
for case-insensitive matching. The following example matches URIs that include the string .html or .htmin
any position.
(以~开头的正则表达式是对大小写敏感的),~*是不关心大小写,下面的URIs匹配的html和html
To find the location that best matches a URI, NGINX Plus first compares the URI to the locations with a prefix string. It then searches the locations with a regular expression.
为了匹配URI,NGINX首先匹配字符串前缀(prefix string),再匹配正则表达式
Higher priority is given to regular expressions, unless the
is used. Among the prefix strings NGINX Plus selects the most specific one (that is, the longest and most complete string). The exact logic for selecting a location to process a request is given below:
如果使用^~修饰符,正则表达式会有更高的优先级。在字符串前缀中,nginx会找到最匹配的那个(最长,最完整的).下面给出了完整的匹配逻辑。
Test the URI against all prefix strings. (URI匹配所有的字符串前缀)
The
an exact match of the URI and a prefix string. If the exact match is found, the search stops.(=修饰符规定了一个精确的匹配,如果改匹配成功,到此结束)
If the
prepends the longest matching prefix string, the regular expressions are not checked.(如果^~修饰符预先加在最长匹配的字符串前缀那里,那么正则表达式不会被检查)
Store the longest matching prefix string.(存储匹配最长的字符串前缀)
Test the URI against regular expressions.(URI和正则表达式匹配)
Break on the first matching regular expression and use the corresponding location.(第一个匹配的正则表达式那里终端,并且使用对应的那个location)
If no regular expression matches, use the location corresponding to the stored prefix string.(如果没有正则表达式匹配,那么使用存储字符串前缀的那个location)
~)
for case-sensitive matching, or the tilde-asterisk (
~*)
for case-insensitive matching. The following example matches URIs that include the string .html or .htmin
any position.
(以~开头的正则表达式是对大小写敏感的),~*是不关心大小写,下面的URIs匹配的html和html
[code]location ~ \.html? { ... }
To find the location that best matches a URI, NGINX Plus first compares the URI to the locations with a prefix string. It then searches the locations with a regular expression.
为了匹配URI,NGINX首先匹配字符串前缀(prefix string),再匹配正则表达式
Higher priority is given to regular expressions, unless the
^~modifier
is used. Among the prefix strings NGINX Plus selects the most specific one (that is, the longest and most complete string). The exact logic for selecting a location to process a request is given below:
如果使用^~修饰符,正则表达式会有更高的优先级。在字符串前缀中,nginx会找到最匹配的那个(最长,最完整的).下面给出了完整的匹配逻辑。
Test the URI against all prefix strings. (URI匹配所有的字符串前缀)
The
=(equals sign) modifier defines
an exact match of the URI and a prefix string. If the exact match is found, the search stops.(=修饰符规定了一个精确的匹配,如果改匹配成功,到此结束)
If the
^~(caret-tilde) modifier
prepends the longest matching prefix string, the regular expressions are not checked.(如果^~修饰符预先加在最长匹配的字符串前缀那里,那么正则表达式不会被检查)
Store the longest matching prefix string.(存储匹配最长的字符串前缀)
Test the URI against regular expressions.(URI和正则表达式匹配)
Break on the first matching regular expression and use the corresponding location.(第一个匹配的正则表达式那里终端,并且使用对应的那个location)
If no regular expression matches, use the location corresponding to the stored prefix string.(如果没有正则表达式匹配,那么使用存储字符串前缀的那个location)
相关文章推荐
- Linux下nginx安装
- dokuwiki在nginx的配置
- ubuntu编译安装nginx
- linux下nginx负载均衡部署
- zabbix 监控 nginx
- nginx windows版本 1024限制
- 解决NGINX+PHP-FPM failed to ptrace(PEEKDATA) Input/output error出错问题
- 解决NGINX+PHP-FPM failed to ptrace(PEEKDATA) Input/output error出错问题
- nginx
- Nginx配置文件nginx.conf 总结
- Linux中为flask框架网站配置uwsgi+nginx服务器
- nginx启动不了
- 配置 nginx 支持 f4v视频格式播放
- Nginx负载均衡(主备)+Keepalived
- 负载均衡之Nginx的安装
- Ubuntu中Nginx的安装与配置
- 通过Nginx服务器获取大文件MD5值的配置方法
- nginx配置虚拟主机
- 关于Nginx+Gunicorn+uwsgi+后端框架到app架构梳理和思考
- ubuntu+web.py+fastcgi+nginx