zoukankan      html  css  js  c++  java
  • nginx-匹配规则

    location 指令的作用是根据用户请求的URI来执行不同的应用。

    locationn使用的语法为

    location [=|~|~*|^~] uri {

      ....

    }

     

    location 语法说明表

     
     
     
     
     
     

    location

    [=|~|~*|^~]

    uri

    {....}

    指令

    匹配标识

    匹配的网站地址

    匹配URI后要执行的配置段

    与~* 的区别

       ~  匹配内容区分大小写

       ~* 匹配内容不区分的小写

       !~ 取反

       ^~ 但多个匹配同时存在,优先匹配 ^~匹配的内容;不做正则表达式的检查 (优先处理)

     

    官方配置示例

    location = / {

        [ configuration A ]

    }

     

    location / {

        [ configuration B ]

    }

     

    location /documents/ {

        [ configuration C ]

    }

     

    location ^~ /images/ {

        [ configuration D ]

    }

     

    location ~* .(gif|jpg|jpeg)$ {

        [ configuration E ]

    }

    "/"请求将匹配配置A,

    "/index.html"请求将匹配配置B,

    "/documents/document.html"请求将匹配配置C,

    "/images/1.gif"请求将匹配配置D,

    "/documents/1.jpg"请求将匹配配置E.

     

    顺序

    不用URI及特殊字符组合匹配

    匹配说明

    1

    location = / {}

    精确匹配 /

    2

    location ^~ /image/{

    匹配常规字符串,不做正则表达式匹配检查

    3

    location ~* .(gif|jpg|jpeg)$ {

    正则匹配

    4

    location /documents/ {

    匹配常规字符串,如果有正则,则优先匹配正则

    5

    location / {

    所有location 都不能匹配后的默认匹配

     

     

     

  • 相关阅读:
    博客第8周
    剑指offer 位运算
    真题
    剑指offer分类刷题(转载)
    PV PVC StorageClass是什么?
    k8s使用rbac实现多租户
    ansible-playbook 使用blockinfile 修改/etc/hosts 主机名
    ansible-playbook 一键部署ntp时间同步 yml
    简单搭建一个HTTP文件下载服务器
    常用docker命令备忘
  • 原文地址:https://www.cnblogs.com/kuku0223/p/7767152.html
Copyright © 2011-2022 走看看