• Nginx location正则表达式


    转:https://www.jianshu.com/p/9fd2ea5b7d12

    location正则表达式书写示例:

    1. 等号(=)

    表示完全匹配规则才执行操作

    location = /index {
        [ configuration A ]    
    }

    URL为 http://{domain_name}/index 时,才会执行配置中操作。

    2. 波浪号(~)

    表示执行正则匹配,但区分大小写

    location ~ /page/d{1,2} {
        [ configuration B ]
    }

    URL 为 http://{domain_name}/page/1 匹配结尾数字为1-99时,配置生效。

    3.波浪号与星号(~*)

    表示执行正则匹配,但 区分大小写

    location ~* /.(jpg|jpeg|gif) {
        [ configuration C ]
    }

    匹配所有url以jpg、jpeg、gif结尾时,配置生效。

    4.脱字符与波浪号(^~)

    表示普通字符匹配,前缀匹配有效,配置生效

    location ^~ /images/ {
    [ cofigurations D ]
    }

    URL 为 http://{domain_name}/images/1.gif 时,配置生效。

    5.@

    定义一个location,用于处理内部重定向

    location @error {
        proxy_pass http://error;
    }

    各字符有效优先级

    = > ^~ > ~/~*
    (~/~*)中有多个正则匹配时,选择正则表达式最长的配置执行。

  • 相关阅读:
    php上传文件大小修改
    flex布局
    restful
    mysql之windows忘记密码
    mysql常用命令
    比较级浅析1
    一般副词的位子
    still讲解
    英语学习法
    as的如下用法
  • 原文地址:https://www.cnblogs.com/jvStarBlog/p/12719433.html
Copyright © 2020-2023  润新知