zoukankan      html  css  js  c++  java
  • nginx 匹配规则小总结

    nginx location

    等号类型(=)的优先级最高,需要精确匹配。一旦匹配成功,则不再查找其他匹配项。
    ^~类型表达式。一旦匹配成功,则不再查找其他匹配项。

    正则表达式类型(~ ~*)的优先级次之。如果有多个location的正则能匹配的话,则使用正则表达式最长的那个。

    (location =) > (location 完整路径) > (location ^~ 路径) > (location ,* 正则顺序) > (location 部分起始路径) > (/)

    nginx 配置 proxy_pass 路径带 / 的问题

    用户访问的 url 为 http://klvchen.com/abc/test.html
    eg:

    #情况1: proxy_pass 后带 / 
    location  /abc/ {
                    proxy_pass http://klvchen.com/;
    } 
    #会被代理成  http://klvchen.com/test.html
    
    #情况2: proxy_pass 后不带 / 
    location  /abc/ {
                    proxy_pass http://klvchen.com;
    } 
    #会被代理成  http://klvchen.com/abc/test.html
    

    常用正则

    .: 匹配除换行符以外的任意字符
    ?: 重复0次或1次
    +: 重复1次或更多次
    *: 重复0次或更多次
    d:匹配数字
    ^: 匹配字符串的开始
    $: 匹配字符串的结束
    {n}: 重复n次
    {n,}: 重复n次或更多次
    [c]: 匹配单个字符c
    [a-z]: 匹配a-z小写字母的任意一个
    小括号()之间匹配的内容,可以在后面通过$1来引用,$2表示的是前面第二个()里的内容。正则里面容易让人困惑的是转义特殊字符。

  • 相关阅读:
    Document
    Document
    Document
    Document
    Document
    Document
    手动版 轮播图
    Echarts tooltip 自定义formatter设置字体颜色
    CSS3中 translate、transform 和 translation 的区别和联系,及开发问题解决
    background 属性及遇到的问题
  • 原文地址:https://www.cnblogs.com/klvchen/p/9353917.html
Copyright © 2011-2022 走看看