zoukankan      html  css  js  c++  java
  • Ngnix location匹配规则

    Ngnix 站点:http://www.nginx.cn

    Location 匹配命令

    ~      波浪线表示执行一个正则匹配,区分大小写.
    ~* 表示执行一个正则匹配,不区分大小写.
    ^~ ^~表示普通字符匹配,如果该选项匹配,只匹配该选项,不匹配别的选项,一般用来匹配目录.
    = 进行普通字符精确匹配.
    @ "@" 定义一个命名的 location,使用在内部定向时,例如 error_page, try_files.

    Location优先级

    Location优先级
    Directives with the = prefix that match the query exactly. If found, searching stops.
    All remaining directives with conventional strings, longest match first. If this match used the ^~ prefix, searching stops.
    Regular expressions, in order of definition in the configuration file.
    If #3 yielded a match, that result is used. Else the match from #2 is used.
    =前缀的指令严格匹配这个查询。如果找到,停止搜索。
    所有剩下的常规字符串,最长的匹配。如果这个匹配使用^〜前缀,搜索停止。
    正则表达式,在配置文件中定义的顺序。
    如果第3条规则产生匹配的话,结果被使用。否则,如同从第2条规则被使用。


    例如

    location  = / {
      # 只匹配"/".
      [ configuration A ] 
    }
    location  / {
      # 匹配任何请求,因为所有请求都是以"/"开始
      # 但是更长字符匹配或者正则表达式匹配会优先匹配
      [ configuration B ] 
    }
    location ^~ /images/ {
      # 匹配任何以 /images/ 开始的请求,并停止匹配 其它location
      [ configuration C ] 
    }
    location ~* .(gif|jpg|jpeg)$ {
      # 匹配以 gif, jpg, or jpeg结尾的请求. 
      # 但是所有 /images/ 目录的请求将由 [Configuration C]处理.   
      [ configuration D ] 
    }

    请求URI例子:

    • / -> 符合configuration A
    • /documents/document.html -> 符合configuration B
    • /images/1.gif -> 符合configuration C
    • /documents/1.jpg ->符合 configuration D

    @location 例子
       error_page 404 = @fetch;

       location @fetch(
          proxy_pass http://fetch;
       )

    原文地址:http://www.nginx.cn/115.html 

  • 相关阅读:
    基础调试命令
    mui 拨打电话
    vue a href="tel" 拨打电话
    vue数据已渲染成 但还是报错 变量 undefined
    表格头部与左侧内容随滚动条位置改变而改变(基于jQuery)
    element popover 不显示/不隐藏问题解决方法
    fatal: The remote end hung up unexpectedly解决办法
    mui.fire 目标页无法监听到 触发事件
    多个定时器任务
    vue router 传参 获取不到query,params
  • 原文地址:https://www.cnblogs.com/shihujiang/p/3494747.html
Copyright © 2011-2022 走看看