On nginx 1.10.1 I'm proxying an external website (not under my control) to cache images locally.
my config is the following:
location ~ /cachedimages/(?<productcode>.*)/(?<size>.*)/image.jpg {
resolver 127.0.0.1;
proxy_pass https://www.externalsite.example/api/getImage/?productcode=$productcode&size=$size;
proxy_cache imgcache;
proxy_cache_valid 200 1d;
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
expires 1M;
access_log off;
add_header 'Cache-Control' "public";
add_header Last-Modified $upstream_http_last_modified;
add_header X-Proxy-Cache $upstream_cache_status;
}
imgcache
is defined has following:
proxy_cache_path /var/cache/nginx/imgcache levels=1:2 keys_zone=imgcache:10m max_size=1g inactive=24h;
The remote server doesn't give the Last-Modified
header:
curl -X GET -I https://www.externalsite.example/api/getImage/?productcode=abc123&size=128
HTTP/1.1 200 OK
Date: Thu, 15 Sep 2016 08:16:07 GMT
Server: Apache
Transfer-Encoding: chunked
Content-Type: image/jpeg
and my server adds some header but not Last-Modified
curl -X GET -I https://www.myserver.com/cachedimages/abc123/128/image.jpg
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 15 Sep 2016 08:33:26 GMT
Content-Type: image/jpeg
Transfer-Encoding: chunked
Connection: keep-alive
Expires: Sat, 15 Oct 2016 08:33:26 GMT
Cache-Control: max-age=2592000
Cache-Control: public
X-Proxy-Cache: HIT
How can I force nginx to read the mtime of the cached (and hit) file and serve it as Last-Modified
header value?