NGINX not caching images or sending added headers

add_header directive and the proxy directive seems to be ignored. I am using nginx as a cdn to serve images and I would like it to cache the images. The below is my sites available for the cdn. The images are served fine but I don't see the X-Cache-Status in the headers nor does it seem to be populating the cache path with any content.

What am I missing?

nginx version: nginx/1.10.0 (Ubuntu)

proxy_cache_path /var/www/html/nginx-cache levels=1:2 keys_zone=cdn:100m max_size=25g inactive=60m use_temp_path=off;

# Expires map
map $sent_http_content_type $expires {
    default                    off;
    text/html                  epoch;
    text/css                   max;
    application/javascript     max;
    ~image/                    max;
}


server {
  listen 80;
  server_name applebeescdn;

  # Proxy Cache
  proxy_cache cdn;
  proxy_cache_key "$host$request_uri $cookie_user";
  proxy_cache_min_uses 1;
  proxy_cache_valid 200 302 120m;
  proxy_cache_valid 404 1m;
  proxy_ignore_headers "Set-Cookie";
  proxy_hide_header "Set-Cookie";
  proxy_cache_use_stale error timeout invalid_header http_500 http_502 http_503 http_504;
  proxy_buffering on;

  location / {
    expires $expires;
    root /var/www/html/;
    add_header 'X-Cache-Status' "$upstream_cache_status" always;
  }

}
2
задан 4 January 2017 в 22:47
1 ответ

Я думаю, вы неправильно понимаете, как использовать proxy_cache . У вас должен быть proxy_pass , если вы используете proxy_cache (т.е. отдельный исходный сервер, для которого этот экземпляр nginx действует как обратный прокси). Вы можете узнать больше о том, как настроить исходный сервер здесь .

3
ответ дан 3 December 2019 в 10:36

Теги

Похожие вопросы