map $upstream_cache_status $cache_status {
  'HIT' 'HIT';
  default $upstream_http_x_cache_status;
}

server {
  server_name edge;
  proxy_cache cache_1;
  proxy_cache_key $host$uri;
  proxy_cache_valid 200 206 301 302 10s;
  add_header X-Cache-Status $cache_status;
  proxy_hide_header X-Cache-Status;
  proxy_set_header Host relay;
  location / {
    proxy_pass http://relay;
  }
}

server {
  server_name relay;
  proxy_cache cache_1;
  proxy_cache_key $host$uri;
  proxy_cache_valid 200 206 301 302 10s;
  add_header X-Cache-Status $upstream_cache_status;
  proxy_hide_header X-Cache-Status;
  proxy_set_header Host origin;
  location / {
    proxy_pass http://origin;
  }
}

내 값이 HIT가 아니면, 윗 relay의 값을 참조하게 설정했다.

마지막 relay는 upstream 값이 없기에, 무조건 기본 값으로 넣어야한다.

반응형

+ Recent posts