First, the route - the Location of use
9.1. The Location grammar rules
Grammar rules: LOCATION [= | ~ | ~ * | ^ ~] / URI / {...}
First match =, followed by matching ^ ~, followed by the positive matching file in order, finally to / generic matches. When there is a match success when stopped matching, processing requests by the current rule matches.
symbol |
meaning |
= |
= Exact matching at the beginning of |
^~ |
~ ^ Represents the beginning of the uri string beginning with a conventional, it can be appreciated (prohibiting regular match) to match url path. |
~ |
~ Represents the beginning of a case-sensitive match regular |
~* |
~ * Represents the beginning of a case-insensitive regular match |
! ~ And! ~ * |
! ~ And! ~ * Are case-sensitive and case-insensitive match does not match the regular |
/ |
Proxy user used (usually a browser) |
Matching rule priorities are as follows:
² = when precise matching hits, stop location action, go directly to the precise matching,
² generally matching (including non-regular) when hit, first collect all the ordinary match, and finally the longest that a comparison
² If the longest match that a general statement is non-regular, direct matching this entry, stop location
² If the longest match is not common that a non-regular, continuing to go down a regular location
² by regular execution order of the code matching, when the first regular location on hit, stop location
9.2. Path matching process
Suppose http request path
http://192.168.0.132:8088/mvc/index?id=2 ,匹配过程如下:
² 将整个url拆解为域名/端口/path/params
² 先由域名/端口,对应到目标server虚拟主机
² path部分参与location匹配,path = path1匹配部分 + path2剩余部分
² 进入location方法体内部流程。
² 若是静态文件处理,则进入目标目录查找文件:root指令时找path1+path2对应的文件;alias指令时找path2对应的文件
² 若是proxy代理,则形如proxy_pass=ip:port时转发path1+path2路径到tomcat;形如proxy_pass=ip:port/xxx时转发path2路径到tomcat。params始终跟随转发。