Nginx配置文件nginx.conf中location的匹配原则

一、空格:默认匹配、普通匹配

location / {
     root /home;
}

二、= :精确匹配(表示匹配到  /home/resources/img/face.png 这张图片)

location = /resources/img/face.png {
    root /home;
}

三、~*:匹配正则表达式,不区分大小写

#符合图片的显示
location ~* .(GIF|jpg|png|jpeg) {
    root /home;
}

四、~:匹配正则表达式,区分大小写

#GIF必须大写才能匹配到
location ~ .(GIF|jpg|png|jpeg) {
    root /home;
}

五、^~:以某个字符路径开头

location ^~ /resources/img {
    root /home;
}

六、

server {
        listen       90;
        server_name  localhost;

        location / {
            root   /home/foodie-shop;
            index  index.html;
        }


        ##一、利用原路径访问
        location /imooc {
            root   /home;
        }

        ##二、利用起别名的方式、访问 给resources起了个别名static
        location /static {
            alias    /home/resources;
        }


    }

 

posted @ 2021-01-20 21:06  Tom-shushu  阅读(498)  评论(0编辑  收藏  举报