刘伟 发表于 2018-11-12 10:13:15

2.Nginx学习-The HTTP Core module

  http core module是Ngnix提供WEB服务的最核心模块,默认被开启。本篇文章将讲述该模块的一些配置
  配置文件结构:
http {  
    server {// virtual website
  
      location{
  
      }
  
    }
  
    server{
  
      location{
  
      }
  
    }
  
}
  Location modifer 匹配规则
  匹配优先级与顺序: = -->No modifer --> ^~ modifier --> ~ or ~* modifier -->no modifier

[*]  = 字符串精准匹配,不支持正则
  server {
  server_name website.com;
  location = /abcd {
  […]
  }
  }
  http://website.com/abcd (exact match 精确匹配)
  http://website.com/ABCD (如果OS忽略大小写,则可以匹配)
  http://website.com/abcd?param1&param2(匹配,忽略query参数)
  http://website.com/abcd/ (不匹配,多了一个slash斜杠)
  http://website.com/abcde (不匹配)

[*]  No modifer :begin with the specifed pattern. You may not use regular expressions
  server {
  server_name website.com;
  location/abcd {
  […]
  }
  }
  http://website.com/abcd (exact match 精确匹配)
  http://website.com/ABCD (如果OS忽略大小写,则可以匹配)
  http://website.com/abcd?param1&param2(匹配,忽略query参数)
  http://website.com/abcd/ (匹配)
  http://website.com/abcde (匹配)

[*]  The ~ modifer :case-sensitive 匹配正则
  server {
  server_name website.com;
  location ~ ^/abcd${
  […]
  }
  }
  http://website.com/abcd (exact match 精确匹配)
  http://website.com/ABCD (不匹配)
  http://website.com/abcd?param1&param2(匹配,忽略query参数)
  http://website.com/abcd/ (不匹配,多了一个斜杠)
  http://website.com/abcde (不匹配)

[*]  The ~* modifer :case-insensitive 匹配正则
  server {
  server_name website.com;
  location ~* ^/abcd${
  […]
  }
  }
  http://website.com/abcd (exact match 精确匹配)
  http://website.com/ABCD (匹配)
  http://website.com/abcd?param1&param2(匹配,忽略query参数)
  http://website.com/abcd/ (不匹配,多了一个斜杠)
  http://website.com/abcde (不匹配)

[*]  The ^~ modifer:if the pattern is matched, Nginx stops searching for other patterns
[*]  The @ modifer : 定义内部location块,可以通过内部跳转访问
  
  


页: [1]
查看完整版本: 2.Nginx学习-The HTTP Core module