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

前端之家收集整理的这篇文章主要介绍了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|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;
        }


    }

 

原文链接:https://www.f2er.com/nginx/997836.html

猜你在找的Nginx相关文章