nginx实战笔记

nginx最佳实践

  • 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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容