缓存配置后,一些图像在 Magneto 上的缓存时间仍然不同

缓存配置后,一些图像在 Magneto 上的缓存时间仍然不同

我在 nginx 上运行 magneto,并且配置了一年的图像缓存,仍然在 gtmetrix 中缓存一些我得到的图像(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分钟)

答案1

我最好的猜测是你还没有将 headers_more 编译到 Nginx 中。要确认你是否已将其添加到你的图像位置块中

add_header XYZ "TESTING";

发布“curl -i”的输出,或者您可以使用 Firefox 和“Live HTTP Headers”插件查看标头。另外,删除“pragma”,它已经过时且没有必要。基本上,复制下面的我的块,至少复制您需要的部分。

如果你需要有关如何使用 headers_mode 构建 Nginx 的说明,请参阅我的教程这里

作为参考,这是我自己的位置博客,它做了类似的事情

# 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
}

相关内容