Nginx未设置Expires和Cache-Control标头

时间:2015-09-01 18:05:23

标签: caching nginx browser-cache expires-header

Chromium Dev Tools抱怨所有资源都显然不可缓存",尽管我在配置中明确添加了相关指令。

我在/etc/nginx/sites-enabled/中有这个文件,它包含在主配置中:

upstream django {
    server unix:///tmp/uwsgi.sock;
}


server {
    listen 80;
    charset utf-8;

    pagespeed on;
    pagespeed FileCachePath /var/ngx_pagespeed_cache;
    pagespeed ModifyCachingHeaders off;
    pagespeed RewriteLevel PassThrough;
    pagespeed EnableFilters collapse_whitespace;

    location /robots.txt {
        alias /home/user/www/staticfiles/robots.txt;
    }

    location /sitemap.xml {
        alias /home/user/www/staticfiles/sitemap.xml;
    }

    # Media: images, icons, video, audio, HTC
    location ~* .+\.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
        expires 1M;
        #access_log off;
        add_header Cache-Control "public";
    }

    # CSS and Javascript
    location ~* .+\.(?:css|js)$ {
        expires max;
        #access_log off;
        add_header Cache-Control "public";
    }

    location ^~ /static/  {
        alias /home/user/www/staticfiles/;
    }

    location / {
        uwsgi_pass django;
        include uwsgi_params;
    }
}

以下是标题:
请求

Accept:image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8,fr;q=0.6,it;q=0.4
Cache-Control:no-cache
Connection:keep-alive
Cookie:csrftoken=waqcxfsiBGAtD9OgVoKXnTxDHcfqiQFJ
Host:streaming-ita.co
Pragma:no-cache
Referer:http://streaming-ita.co/static/CACHE/css/1d69e50f86a3.css
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36

响应

Accept-Ranges:bytes
Connection:keep-alive
Content-Length:1015
Content-Type:image/png
Date:Tue, 01 Sep 2015 20:07:35 GMT
ETag:"55e21ced-3f7"
Last-Modified:Sat, 29 Aug 2015 20:58:21 GMT
Server:nginx/1.8.0

我看到Pragma: no-cacheCache-Control: no-cache存在,但我确实没有添加它。 Chrome是否添加了它?

0 个答案:

没有答案