我使用此代码将expires添加到静态文件中:
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires 30d;
add_header Pragma public;
add_header Cache-Control “public”;
log_not_found off;
}
我在virutual目录/ image /中有一些随机图像。当上面的代码在Nginx中时,随机图像得到404.
我不需要为目录/ image /过期。对于此目录,代码不应运行。怎么用Nginx语言编写这样的东西:
If not /image/
{
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$
{
expires 30d;
add_header Pragma public;
add_header Cache-Control “public”;
log_not_found off;
}
}
答案 0 :(得分:0)
试试这个
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$
{
if ($request_uri !~ ^/image/.*) {
expires 30d;
}
add_header Pragma public;
add_header Cache-Control "public";
log_not_found off;
}