Nginx 이미지 헤더 캐시가 업데이트되지 않습니다.

Nginx 이미지 헤더 캐시가 업데이트되지 않습니다.

다음 위치에 이미지 파일이 있습니다.https://www.example.com/img/bart-had-a-groove.gif

그리고 이것은 내 사이트 구성의 유일한 캐시 블록이며 전역 nginx.conf에는 캐싱 설정이 없습니다.

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, no-transform, max-age=2628000";
}

이제 내 헤더가 로 설정되어 있는 것을 볼 수 있지만 Cache-Control "public, no-transform, max-age=2628000";이미지를 컬링하면 다음과 같은 결과가 curl -X GET -I https://www.example.com/img/bart-had-a-groove.gif나타납니다.

HTTP/1.1 200 OK
Content-Type: image/gif
Connection: keep-alive
Server: nginx/1.13.9
Content-Length: 771510
Last-Modified: Fri, 17 Feb 2017 17:26:23 GMT
ETag: "58a7323f-bc5b6"
Pragma: public
Cache-Control: public
Accept-Ranges: bytes
Date: Mon, 19 Mar 2018 21:49:33 GMT
Expires: Wed, 18 Apr 2018 21:49:33 GMT

Cache-Control: public구성과 일치하지 않는 것을 볼 수 있습니다 . 그 부분이 빠졌네요 no-transform, max-age=2628000.

나는 systemctl stop nginx && systemctl start nginx && systemctl reload nginx모든 변화 후에 달려갑니다.

업데이트 나머지 서버 블록:

server {
  listen 80;
  listen 443;
  server_name example.com;
  return 301 https://www.$server_name$request_uri;
}

server {
  listen 80;
  listen 443 ssl http2;
  root /var/www/example.com/htdocs/;

  index index.html index.htm;

  server_name www.example.com;

  location / {
    autoindex on;
    try_files $uri $uri/ =404;    
  }

  location ~ \.php$ {
    fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
    # Security note: If you're running a version of PHP older than the
    # latest 5.3, you should have "cgi.fix_pathinfo = 0;" in php.ini.
    # See http://serverfault.com/q/627903/94922 for details.
    include fastcgi_params;
    # Block httpoxy attacks. See https://httpoxy.org/.
    fastcgi_param HTTP_PROXY "";
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param QUERY_STRING $query_string;
    fastcgi_intercept_errors on;
    # PHP 5 socket location.
    #fastcgi_pass unix:/var/run/php5-fpm.sock;
    # PHP 7 socket location.
    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
  }

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, no-transform, max-age=2628000";
}

  pagespeed on;
  # Needs to exist and be writable by nginx.  Use tmpfs for best performance.
  pagespeed FileCachePath /var/ngx_pagespeed_cache;
  # Ensure requests for pagespeed optimized resources go to the pagespeed handler
  # and no extraneous headers get set.
  location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
    add_header "" "";
  }
  location ~ "^/pagespeed_static/" { }
  location ~ "^/ngx_pagespeed_beacon$" { }
}

답변1

"Cache-Control" 헤더와 관련하여 두 개의 상관 구성 지시문을 사용하고 있습니다(아래 참조). 만 사용하는 것이 좋습니다add_header"Cache-Control" 헤더의 "no-transform" 지시문을 높이 평가합니다.

1M 만료;

--> "Cache-Control" 및 "Expires" 헤더를 설정합니다.

문서 보기:

"Expires" 및 "Cache-Control" 응답 헤더 추가 또는 수정을 활성화하거나 비활성화합니다.

add_header Cache-Control "공개, 변환 없음, max-age=2628000";

--> "Cache-Control" 헤더를 수동으로 설정합니다.

관련 정보