资源未缓存(304未修改)

时间:2015-01-12 13:47:08

标签: caching nginx response

我想获得304未修改或200缓存响应,但我每次都会得到200 OK响应。我正在使用nginx和firefox开发人员来检查响应。

在回复标题下方:

Cache-Control: max-age=315360000, public
Connection: keep-alive
Content-Disposition: inline; filename="catHuis.jpg"
Content-Length: 6640
Content-Type: image/jpeg
Date: Mon, 12 Jan 2015 13:45:33 GMT
Expires: Thu, 31 Dec 2037 23:55:55 GMT
Last-Modified: Mon, 12 Jan 2015 12:40:00 GMT
Pragma: public
Server: nginx/1.2.1

我用这些标题得到200 OK。显然,这个日期在未来是非常遥远,但我绝望并且使用非常过期的标题测试它。任何人都能指出我的方向吗?我一定错过了什么。

这是当前的nginx配置:

listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.php index.html index.htm;
server_name mydomain.com;
autoindex off;
expires max;
access_log off;
add_header Pragma public;
add_header Cache-Control public;

1 个答案:

答案 0 :(得分:0)

尝试静态资源的位置规则,如下所示:

location ~* \.(txt|ico|css|js|bmp|jpg|jpeg|gif|png|svg|swf|avi|mp4|webm|pdf|mel|rar|zip|bin)$ {
  expires max;
  access_log off;
  add_header Cache-Control public;
}