我正在nginx上运行一个magneto磁盘,并且我已经configuration了一些仍然在gtmetrix中的caching图像(5分钟)
server { listen 0.0.0.0:443 default_server ssl; server_name somedomain.com; server_name www.somedomain.com; server_name ipv4.somedomain.com; pagespeed EnableFilters prioritize_critical_css; pagespeed EnableFilters extend_cache; ssl_certificate /usr/local/psa/var/certificates/cert-TANhO4; ssl_certificate_key /usr/local/psa/var/certificates/cert-TANhO4; ssl_client_certificate /usr/local/psa/var/certificates/cert-R31hv6; ssl_session_timeout 5m; ssl_protocols SSLv2 SSLv3 TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; client_max_body_size 128m; root "/var/www/vhosts/somedomain/httpdocs"; access_log "/var/www/vhosts/system/somedomain/logs/proxy_access_ssl_log"; error_log "/var/www/vhosts/system/somedomain/logs/proxy_error_log"; location / { proxy_pass https://192.168.1.232:7081; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Accel-Internal /internal-nginx-static-location; access_log off; } location /internal-nginx-static-location/ { alias /var/www/vhosts/somedomain/httpdocs/; add_header X-Powered-By PleskLin; internal; } # CSS and Javascript location ~* \.(css|js)$ { access_log off; log_not_found off; add_header Pragma public; add_header Cache-Control "max-age=30d,public"; expires 30d; } # Images location ~* \.(ico|jpg|webp|jpeg|gif|png|bmp|zip|woff)$ { access_log off; log_not_found off; add_header Pragma public; add_header Cache-Control "public, max-age=1y"; expires 1y; }
}
例如: http://somesite/images/siteimages/category_tiles_109x109/xgold-hollow-cross-tile.gif.pagespeed.ic.EbboFWD5Wz.png (5分钟)
我最好的猜测是你没有编译header_more到Nginx。 确认是否在图像位置块中添加了此项
add_header XYZ "TESTING";
发布“curl -i”的输出,或者您可以看到带有Firefox和“Live HTTP Headers”插件的头文件。 另外,放弃“杂注”,这是旧的和不必要的。 基本上,复制下面的块,至less是你需要的部分。
如果你想了解如何使用headers_mode构buildNginx,请参阅我的教程。
参考这里是我自己的位置博客,做了类似的事情
# Cache images on the client. Don't log errors or access. Block hotlinking. location ~* \.(jpg|jpeg|png|gif|css|js|ico)$ { log_not_found off; access_log off; valid_referers none blocked server_names ~($host) ~(googleusercontent|google|bing|yahoo); if ($invalid_referer) { rewrite (.*) /stop-stealing-images.png redirect; # drop the 'redirect' flag for redirect without URL change (internal rewrite) } # Set up caching - 8 days for static resources. Remove the old unnecessary Pragma and hide the server version more_clear_headers "Cache-Control"; add_header Cache-Control "public, max-age=691200, s-maxage=691200"; more_clear_headers Server; more_clear_headers "Pragma"; more_clear_headers "Expires"; # add_header Z_LOCATION "wpmu STATIC RESOURCES REGEX"; add_header URI $uri; # Nginx Debugging }