【问题标题】:Expires headers for url rewrite rules in nginx过期 nginx 中 url 重写规则的标头
【发布时间】:2013-10-21 19:26:13
【问题描述】:

在我的 nginx 配置中,我有一些图像的 url 重写规则,如下所示:

location / {
    rewrite ^/custom/path/(.*)/(.*)-(.*).jpg$ /media/images/products/$1/$3.jpg last;
}

它们工作得很好。我还尝试为所有静态资源(图像、css、js)设置Expire 标头。我为此添加了以下块:

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    expires 1y;
}

这适用于除具有 url 重写规则(返回 404 Not found)的图像之外的所有内容。有谁知道我在这里做错了什么?

【问题讨论】:

    标签: url-rewriting nginx http-headers


    【解决方案1】:

    将重写规则移动到与过期规则相同的块内就可以了:

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires 1y;
    
        rewrite ^/custom/path/(.*)/(.*)-(.*).jpg$ /media/images/products/$1/$3.jpg last;
    }
    

    【讨论】:

      猜你喜欢
      • 2013-10-12
      • 1970-01-01
      • 2017-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-17
      • 1970-01-01
      相关资源
      最近更新 更多