location /html/ {
alias /mnt/;
access_log /dev/null;
error_log /dev/null;
}
location ~ .*.(html)$
{
expires 15m;
access_log /dev/null;
}
我的理解为 第一个Location 访问 html 的目录 指定到 mnt目录下 第二个location 是以任意.html结尾的在浏览器 过期时间为15m分钟。
但是如果这两个location 同时存在的话,而我第一个location 则无法实现,求教下原因,谢谢
原因并非是冲突,而是匹配顺序的问题
你这里的原因是,正则匹配比前面的优先
所有 /html/ 下的 html 文件被第二个 location 优先匹配了
建议修改为
这样 /html/ 下的 html 文件会使用 /mnt/ 目录下的文件
其他 html 文件也会添加 cache-control 头
另外 access_log 支持 off 参数,可以省去 IO 操作