04.location
[toc]{type: “ol”, level: [2, 3, 4, 5]}
location匹配规则
location = / {
# 精确匹配/ ,后面不能带其他的东西
[ configuration A ]
}
location / {
# 所有的以/开头的地址
[ configuration B ]
}
location /documents/ {
# 只匹配/documents/
[ configuration C ]
}
location ^~ /images/ {
# 匹配以/images/开头。
~严格大小写
[ configuration D ]
}
location ~* \.(gif|jpg|jpeg)$ {
# 以(gif|jpg|jpeg)结尾的文件
# ~* 不区分大小写
[ configuration E ]
}
# 优先级
# = > 完整路径 > ^~ > /
location分离
server {
listen 80 ;
server_name www.taobao.com taobao.com;
location / {
proxy_pass http://192.168.21.131:82;
}
location ~*\.(jpg|gif|png)$ {
root /data/img;
}
}
status
location /status {
stub_status on;
}
压缩
gzip on
# 提高响应速度节省带宽