我的网络服务器上有一个目录,其中包含我不想缓存的图像.
Nginx是Apache的前端.我在Nginx.conf中为静态资源启用了缓存:
server {
listen 80;
server_name www.mydomain.com mydomain.com;
location / {
root /home/somedomain/public_html/site;
proxy_pass http://backend;
include /etc/Nginx/proxy.conf;
}
location ~* \.(css|js)${
root /home/somedomain/public_html/site;
add_header Last-Modified: $date_gmt;
expires 1y;
access_log off;
}
location ~* \.(jpg|jpeg|gif|png|ico|bmp|swf)${
root /home/somedomain/public_html/site;
expires max;
access_log off;
}
location ~ \.PHP {
proxy_pass http://backend;
include /etc/Nginx/proxy.conf;
}
}
我试图添加到最后:
location /home/somedomain/public_html/site/dontcache/ \.png {
root /home/somedomain/public_html/site/dontcache;
expires off;
}
也尝试过期-1;并且到期1米;但所有这些似乎都不起作用.
我知道这很简单,但我无法理解为什么它对我不起作用.
最佳答案
location ^~ /home/somedomain/public_html/site/dontcache/ {
root /home/somedomain/public_html/site/dontcache;
expires epoch;
}
here描述了位置指令的匹配顺序