- nginx location详解
Syntax: location [ = | ~ | ~* | ^~ ] uri { ... }
location @name { ... }
Default: —
Context: server, location
### 匹配规则介绍
A location can either be defined by a prefix string, or by a regular expression.
Regular expressions are specified with the preceding “~*” modifier (for case-
insensitive matching), or the “~” modifier (for case-sensitive matching). To
find location matching a given request, nginx first checks locations defined
using the prefix strings (prefix locations). Among them, the location with the
longest matching prefix is selected and remembered. Then regular expressions are
checked, in the order of their appearance in the configuration file. The search
of regular expressions terminates on the first match, and the corresponding
configuration is used. If no match with a regular expression is found then the
configuration of the prefix location remembered earlier is used.
- server_name参数配置
- nginx中root和alias命令都是指定一个路径进行资源定位,初学者可能会把两者搞混,现博主把二者的区别整理如下,好了废话不多说,直接上代码
root的使用
location /assets/ {
root /git/shortUrl/dist/;
}
当user访问http://domain/assets/a.js
的时,nginx把请求映射为/git/shortUrl/dist/assets/a.js
alias的使用
location /assets/ {
alias /git/shortUrl/dist/;
}
当user访问http://domain/assets/a.js
的时,nginx把请求映射为/git/shortUrl/dist/a.js