server {
listen 89;
server_name localhost;
location / {
root html;
index imooc.html;
}
}
server {
listen 89;
server_name localhost;
# =是精准匹配,可以在浏览器中访问ip:89/imooc/img/face1.png,访问face2.png就无法访问了
# 测试时在/home/imooc/img目录下放了图片,访问 /imooc/img/face1.png会/home目录下寻找
location = /imooc/img/face1.png {
root /home;
}
}
server {
listen 92;
server_name localhost;
# 正则表达式,*代表不区分大小写
location ~* \.(GIF|png|bmp|jpg|jpeg) {
root /home;
}
}
server {
listen 93;
server_name localhost;
# ^~,以某个字符路径开头的请求,只能访问这个路径下的资源
location ^~ /imooc/img {
root /home;
}
}
来源:oschina
链接:https://my.oschina.net/liwanghong/blog/4267233