我的 nginx/pagespeed 模組有問題。首次頁面載入時映像快取時間預設為 5 分鐘。
我的nginx.conf中有:
##
# PageSpeed
##
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
pagespeed Domain https://example.com;
pagespeed Domain *.example.com;
pagespeed MapOriginDomain "http://localhost" "https://example.com";
pagespeed LoadFromFile "https://example.com" "/usr/share/nginx/www/";
pagespeed LoadFromFileRuleMatch Disallow \.php$;
pagespeed XHeaderValue "Powered By ngx_pagespeed";
pagespeed ListOutstandingUrlsOnError on;
pagespeed EnableFilters extend_cache;
# image related
pagespeed EnableFilters rewrite_images;
pagespeed EnableFilters convert_gif_to_png;
pagespeed EnableFilters convert_jpeg_to_progressive;
pagespeed EnableFilters strip_image_color_profile;
pagespeed EnableFilters strip_image_meta_data;
pagespeed EnableFilters jpeg_subsampling;
pagespeed EnableFilters lazyload_images;
# code related
pagespeed EnableFilters collapse_whitespace;
# DNS related
pagespeed EnableFilters insert_dns_prefetch;
# JS related
pagespeed UseExperimentalJsMinifier on;
pagespeed EnableFilters rewrite_javascript;
pagespeed EnableFilters combine_javascript;
# css related
pagespeed EnableFilters rewrite_css;
pagespeed EnableFilters prioritize_critical_css;
pagespeed EnableFilters combine_css;
pagespeed EnableFilters outline_css;
pagespeed EnableFilters flatten_css_imports;
如何修改預設的 5 分鐘快取時間?如何透過 pagespeed 模組在首次頁面載入時傳遞圖像?
這沒有幫助:
location ~* \.(jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
expires 1y;
access_log off;
add_header Cache-Control "public";
try_files $uri =404;
}
location ~* \.(pdf|js|css|swf)$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
try_files $uri =404;
}
答案1
從文件
當 PageSpeed 透過 HTTP 或 HTTPS 取得資源時,它會檢查 Expires 和 Cache-Control 標頭以確定更新快取的頻率。當這些標頭未指定逾時時,將使用 5 分鐘的預設逾時。若要覆蓋此設置,請指定:
pagespeed ImplicitCacheTtlMs implicit_cache_ttl_in_milliseconds;