一、空格:默认匹配、普通匹配
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;
}
}
Original: https://www.cnblogs.com/Tom-shushu/p/14290293.html
Author: Tom-shushu
Title: Nginx配置文件nginx.conf中location的匹配原则
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/608179/
转载文章受原作者版权保护。转载请注明原作者出处!