nginx server_name 规则:

1.确切的server_name匹配

例如:

server {
listen ;
server_name www.luwen.cc luwen.cc;
...
}

2.以*通配符开始的最长字符串

server {
listen ;
server_name *.luwen.cc;
...
}

3.以*通配符结束的最长字符串

server {
listen ;
server_name www.*;
...
}

这两条有两个特别要注意的事项:

通配符名字只可以在名字的起始处或结尾处包含一个星号,并且星号与其他字符之间用点分隔。所以,“www.*.luwen.cc”和“w*.luwen.cc”都是非法的。

4.匹配正则表达式

server {
listen ;
server_name ~^(.+)-www\.luwen\.cc$;
...
}

server_name正则表达式应用:

server_name指令一项很实用的功能便是可以在使用正则表达式的捕获功能.nginx使用的正则表达式兼容PCRE。为了使用正则表达式,虚拟主机名必须以波浪线“~”起始否则该名字会被认为是个确切的名字:

如上4

如果表达式含星号,则会被认为是个通配符名字(而且很可能是一个非法的通配符名字)。不要忘记设置“^”和“$”锚点,语法上它们不是必须的,但是逻辑上是的。同时需要注意的是,域  名中的点“.”需要用反斜线“\”转义。含有“{”和“}”的正则表达式需要被引用

如上4

nginx sever_name正则的更多相关文章

  1. nginx location正则写法

    nginx location正则写法 一个示例: location = / { # 精确匹配 / ,主机名后面不能带任何字符串 [ configuration A ] } location / { # ...

  2. nginx location正则写法(转载)

    nginx location正则写法 一个示例: location = / { # 精确匹配 / ,主机名后面不能带任何字符串 [ configuration A ] } location / { # ...

  3. nginx rewrite正则子组最多匹配到$9

    nginx rewrite正则匹配()匹配子组最多匹配到$9,就是从$0到$9 当需要匹配更多子组时,可通过变量来实现 if ($uri ~ ^/forum-15/sortid-74/(.*?)(la ...

  4. nginx location正则

    nginx location正则写法 一个示例: location = / { # 精确匹配 / ,主机名后面不能带任何字符串 [ configuration A ] } location / { # ...

  5. nginx location 正则匹配

    nginx 统计语句1.根据访问IP统计UV awk '{print $1}' access.log|sort | uniq -c |wc -l2.统计访问URL统计PV awk '{print $7 ...

  6. nginx grok 正则错误的输出情况

    nginx 配置: http { include mime.types; default_type application/octet-stream; log_format main '$http_h ...

  7. nginx 常见正则匹配符号表示

    1.^: 匹配字符串的开始位置: 2. $:匹配字符串的结束位置: 3..*: .匹配任意字符,*匹配数量0到正无穷: 4.\. 斜杠用来转义,\.匹配 . 特殊使用方法,记住记性了: 5.(值1|值 ...

  8. Nginx location 正则篇

    location 前缀 没有前缀               匹配以指定模式开头的location =                          精准匹配,不是以指定模式开头 ~       ...

  9. nginx的正则

    ~      为区分大小写的匹配. ~*     不区分大小写的匹配(匹配firefox的正则同时匹配FireFox). !~     不匹配的 !~*    不匹配的 .     匹配除换行符以外的 ...

随机推荐

  1. Coderforces 85 D. Sum of Medians(线段树单点修改)

    D. Sum of Medians time limit per test 3 seconds memory limit per test 256 megabytes input standard i ...

  2. [P1580] yyy loves Easter_Egg I

    Link: P1580 传送门 Solution: 拿来练练字符串的读入: 1.$gets()$相当于$c++$中的$getline()$,但返回值为指针!(无数据时为NULL) (都读入换行符,并将 ...

  3. 【矩阵乘法】bzoj2326 [HNOI2011]数学作业

    http://hzwer.com/2831.html #include<cstdio> #include<iostream> #include<vector> us ...

  4. 【二分答案】【最大流】bzoj1305 [CQOI2009]dance跳舞

    http://hzwer.com/1986.html #include<cstdio> #include<algorithm> #include<queue> #i ...

  5. 【模拟】bzoj2295 【POJ Challenge】我爱你啊

    #include<cstdio> #include<cstring> using namespace std; int n; char s[100001],table[]=&q ...

  6. 【前缀和】【前缀MAX】洛谷 P1351 NOIP2014提高组 day1 T2 联合权值

    不难发现,树中与某个点距离为2的点只可能是它的父亲的父亲.儿子的儿子 或者 兄弟,分类讨论一下即可. 只有对于兄弟我们不能暴力搞,维护一下每个节点的所有儿子的前缀和.前缀MAX就行了. #includ ...

  7. webstorm 2016

    2017.2.27更新 选择“license server” 输入:http://idea.imsxm.com/ 2016.2.2 版本的破解方式: 安装以后,打开软件会弹出一个对话框:选择“lice ...

  8. IOS之Block的应用-textFeild的回调应用

    Block的一点优点为可以省略回调函数,简化代码今天我就应用了以下. 以下是代码片段. _testTextField1=[[MyTextField alloc] init]; [self.view a ...

  9. JavaEE学习路线图

    http://www.cnblogs.com/gaoming7122/archive/2012/11/20/2778308.html

  10. PHP图片的类型将其自动编码成base64

    <!--根据图片的类型将其自动编码成base64--><html><head><?php$file="test.jpg";$type=ge ...