Possible to modify response headers from a proxied request before the response is written do the cache? (modified headers should be written to disk)

Manuel manuel.baesler at gmail.com
Mon Mar 11 23:57:59 UTC 2019


Hello,

nginx writes the rsponse from a proxy to disk. eg.
[...]
Server: nginx
Date: Mon, 11 Mar 2019 23:23:28 GMT
Content-Type: image/png
Content-Length: 45360
Connection: close
Expect-CT: max-age=0, report-uri="
https://openstreetmap.report-uri.com/r/d/ct/reportOnly"
ETag: "314b65190a8968893c6c400f29b13369"
Cache-Control: max-age=126195
Expires: Wed, 13 Mar 2019 10:26:43 GMT
Access-Control-Allow-Origin: *
X-Cache: MISS from trogdor.openstreetmap.org
X-Cache-Lookup: HIT from trogdor.openstreetmap.org:3128
Via: 1.1 trogdor.openstreetmap.org:3128 (squid/2.7.STABLE9)
Set-Cookie: qos_token=031042; Max-Age=3600; Domain=openstreetmap.org; Path=/
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
[...]

is it possible to modify the Cache-Control and Expires header before the
response is written to disk?

The config:

      location /tiles/ {
                proxy_http_version 1.1;
                proxy_ignore_headers "Cache-Control" "Expires" "Set-Cookie";
                proxy_cache_valid any 30d;

                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X_FORWARDED_PROTO https;
                proxy_set_header Host $proxy_host;
                proxy_ssl_server_name on;
                proxy_ssl_name $proxy_host;

                proxy_ssl_certificate     /etc/nginx/cert.pem;
                proxy_ssl_certificate_key /etc/nginx/key.pem;

                expires 30d;
                proxy_cache_lock on;
                proxy_cache_valid  200 302  30d;
                proxy_cache_valid  404      1m;
                proxy_cache_key "$request_uri";
                proxy_redirect off;
                proxy_cache_use_stale error timeout http_500 http_502
http_503 http_504;
                add_header X-Cache-Status $upstream_cache_status;

                # add_header Cache-Control public;
                add_header Last-Modified "";
                add_header ETag "";

                proxy_cache tiles;
                proxy_pass https://openstreetmap_backend/;
        }

The problem is: the cached tiles on disk do not have "Cache-Control:
max-age=2592000" but "Cache-Control: max-age=126195" regardless of setting
proxy_ignore_headers "Cache-Control".
I assumed that setting proxy_ignore_headers "Cache-Control"; and "expires
30d;" will remove the header from the response and write the corresponding
"Cache-Control" and "Expires" with the 30d.


Or do I have to do this:

browser ->
nginx, caches and if necessary requests new tile via ->
nginx, sets expires: 30d; calls tileserver

Kind regards,
Manuel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20190312/39c092dd/attachment.html>


More information about the nginx mailing list