I am using tileserver-gl and want to use Varnish to cache the tiles. Varnish is working with nginx, that is taking care of the SSL. The pbf tiles return Age:0 in the header (and a MISS), while the Date and Expires headers keep their value between reloads. What am I doing wrong? In nginx I am using the following parameters
expires 2d;
add_header Cache-Control "public, no-transform";
Here's my .vcl
sub vcl_recv {
unset req.http.cookie; #added as a test, nothing changed so don't know if I should keep it
}
sub vcl_backend_response {
}
sub vcl_deliver {
if (obj.hits > 0) { # Add debug header to see if it's a HIT/MISS and the number of hits
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
}
Here's response header for one of the pbf tiles. They all give similar results, with Age: 0
Accept-Ranges: bytes
Access-Control-Allow-Origin: *
Age: 0
Cache-Control: max-age=172800, public, no-transform
Content-Encoding: gzip
Content-Length: 44891
Content-Type: application/x-protobuf
Date: Fri, 09 Dec 2022 10:30:34 GMT
ETag: W/"af5b-yQTY5UUgiSJNWC0axguA5dmojbI"
Expires: Sun, 11 Dec 2022 10:30:34 GMT
Last-Modified: Wed, 23 Nov 2022 09:25:23 GMT
Server: nginx/1.18.0 (Ubuntu)
Vary: Accept-Encoding
Via: 1.1 varnish (Varnish/6.6)
X-Cache: MISS
X-Varnish: 557061
EDIT
Tried Thijs suggestion, here's the output
* << Request >> 98318
- Begin req 98317 rxreq
- Timestamp Start: 1670854870.784403 0.000000 0.000000
- Timestamp Req: 1670854870.784403 0.000000 0.000000
- VCL_use boot
- ReqStart 127.0.0.1 38402 a0
- ReqMethod GET
- ReqURL /data/2017-07-03_europe_italy/0/0/0.pbf
- ReqProtocol HTTP/1.0
- ReqHeader X-Forwarded-Host: tiles.urbismap.com
- ReqHeader X-Real_IP: 93.41.126.66
- ReqHeader X-Forwarded-For: 93.41.126.66
- ReqHeader X-Forwarded-Proto: https
- ReqHeader Host: tiles.urbismap.com
- ReqHeader Connection: close
- ReqHeader User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36
- ReqHeader Accept: */*
- ReqHeader Sec-Fetch-Site: same-origin
- ReqHeader Sec-Fetch-Mode: cors
- ReqHeader Sec-Fetch-Dest: empty
- ReqHeader Referer: https://tiles.urbismap.com/styles/basemap/
- ReqHeader Accept-Encoding: gzip, deflate, br
- ReqHeader Accept-Language: it-IT,it;q=0.9
- ReqUnset X-Forwarded-For: 93.41.126.66
- ReqHeader X-Forwarded-For: 93.41.126.66, 127.0.0.1
- VCL_call RECV
- VCL_return hash
- ReqUnset Accept-Encoding: gzip, deflate, br
- ReqHeader Accept-Encoding: gzip
- VCL_call HASH
- VCL_return lookup
- VCL_call MISS
- VCL_return fetch
- Link bereq 98319 fetch
- Timestamp Fetch: 1670854870.792969 0.008566 0.008566
- RespProtocol HTTP/1.1
- RespStatus 200
- RespReason OK
- RespHeader Server: nginx/1.18.0 (Ubuntu)
- RespHeader Date: Mon, 12 Dec 2022 14:21:10 GMT
- RespHeader Content-Type: application/x-protobuf
- RespHeader Content-Length: 31578
- RespHeader Access-Control-Allow-Origin: *
- RespHeader Content-Encoding: gzip
- RespHeader Last-Modified: Wed, 23 Nov 2022 09:25:23 GMT
- RespHeader ETag: W/"7b5a-Lgi1EP0ZRDWVK1iX+VP47MXHk2M"
- RespHeader Expires: Wed, 14 Dec 2022 14:21:10 GMT
- RespHeader Cache-Control: max-age=172800, public, no-transform
- RespHeader Vary: Accept-Encoding
- RespHeader X-Varnish: 98318
- RespHeader Age: 0
- RespHeader Via: 1.1 varnish (Varnish/6.6)
- VCL_call DELIVER
- RespHeader X-Cache: MISS
- VCL_return deliver
- Timestamp Process: 1670854870.793004 0.008600 0.000034
- Filters
- RespHeader Accept-Ranges: bytes
- RespHeader Connection: close
- Timestamp Resp: 1670854870.794239 0.009835 0.001235
- ReqAcct 555 0 555 524 31578 32102
- End
** << BeReq >> 98319
-- Begin bereq 98318 fetch
-- VCL_use boot
-- Timestamp Start: 1670854870.784497 0.000000 0.000000
-- BereqMethod GET
-- BereqURL /data/2017-07-03_europe_italy/0/0/0.pbf
-- BereqProtocol HTTP/1.0
-- BereqHeader X-Forwarded-Host: tiles.urbismap.com
-- BereqHeader X-Real_IP: 93.41.126.66
-- BereqHeader X-Forwarded-Proto: https
-- BereqHeader Host: tiles.urbismap.com
-- BereqHeader User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36
-- BereqHeader Accept: */*
-- BereqHeader Sec-Fetch-Site: same-origin
-- BereqHeader Sec-Fetch-Mode: cors
-- BereqHeader Sec-Fetch-Dest: empty
-- BereqHeader Referer: https://tiles.urbismap.com/styles/basemap/
-- BereqHeader Accept-Language: it-IT,it;q=0.9
-- BereqHeader X-Forwarded-For: 93.41.126.66, 127.0.0.1
-- BereqHeader Accept-Encoding: gzip
-- BereqProtocol HTTP/1.1
-- BereqHeader X-Varnish: 98319
-- VCL_call BACKEND_FETCH
-- VCL_return fetch
-- Timestamp Fetch: 1670854870.784543 0.000045 0.000045
-- Timestamp Connected: 1670854870.784548 0.000050 0.000005
-- BackendOpen 31 default 127.0.0.1 8080 127.0.0.1 41766 reuse
-- Timestamp Bereq: 1670854870.784608 0.000111 0.000060
-- Timestamp Beresp: 1670854870.792781 0.008283 0.008172
-- BerespProtocol HTTP/1.1
-- BerespStatus 200
-- BerespReason OK
-- BerespHeader Server: nginx/1.18.0 (Ubuntu)
-- BerespHeader Date: Mon, 12 Dec 2022 14:21:10 GMT
-- BerespHeader Content-Type: application/x-protobuf
-- BerespHeader Content-Length: 31578
-- BerespHeader Connection: keep-alive
-- BerespHeader Access-Control-Allow-Origin: *
-- BerespHeader Content-Encoding: gzip
-- BerespHeader Last-Modified: Wed, 23 Nov 2022 09:25:23 GMT
-- BerespHeader ETag: W/"7b5a-Lgi1EP0ZRDWVK1iX+VP47MXHk2M"
-- BerespHeader Expires: Wed, 14 Dec 2022 14:21:10 GMT
-- BerespHeader Cache-Control: max-age=172800
-- BerespHeader Cache-Control: public, no-transform
-- TTL RFC 172800 10 0 1670854871 1670854871 1670854870 1671027670 172800 cacheable
-- VCL_call BACKEND_RESPONSE
-- VCL_return deliver
-- Timestamp Process: 1670854870.792827 0.008329 0.000046
-- Filters testgunzip
-- BerespHeader Vary: Accept-Encoding
-- Storage malloc s0
-- Fetch_Body 3 length stream
-- Gzip u F - 31578 51339 80 141523 252560
-- BackendClose 31 default recycle
-- Timestamp BerespBody: 1670854870.794161 0.009664 0.001334
-- Length 31578
-- BereqAcct 552 0 552 426 31578 32004
-- End
* << Request >> 98350
- Begin req 98349 rxreq
- Timestamp Start: 1670855034.759301 0.000000 0.000000
- Timestamp Req: 1670855034.759301 0.000000 0.000000
- VCL_use boot
- ReqStart 127.0.0.1 47736 a0
- ReqMethod GET
- ReqURL /data/2017-07-03_europe_italy/0/0/0.pbf
- ReqProtocol HTTP/1.0
- ReqHeader X-Forwarded-Host: tiles.urbismap.com
- ReqHeader X-Real_IP: 93.41.126.66
- ReqHeader X-Forwarded-For: 93.41.126.66
- ReqHeader X-Forwarded-Proto: https
- ReqHeader Host: tiles.urbismap.com
- ReqHeader Connection: close
- ReqHeader User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36
- ReqHeader Accept: */*
- ReqHeader Sec-Fetch-Site: same-origin
- ReqHeader Sec-Fetch-Mode: cors
- ReqHeader Sec-Fetch-Dest: empty
- ReqHeader Referer: https://tiles.urbismap.com/styles/basemap/
- ReqHeader Accept-Encoding: gzip, deflate, br
- ReqHeader Accept-Language: it-IT,it;q=0.9
- ReqUnset X-Forwarded-For: 93.41.126.66
- ReqHeader X-Forwarded-For: 93.41.126.66, 127.0.0.1
- VCL_call RECV
- VCL_return hash
- ReqUnset Accept-Encoding: gzip, deflate, br
- ReqHeader Accept-Encoding: gzip
- VCL_call HASH
- VCL_return lookup
- Hit 98319 172636.033479 10.000000 0.000000
- VCL_call HIT
- VCL_return deliver
- RespProtocol HTTP/1.1
- RespStatus 200
- RespReason OK
- RespHeader Server: nginx/1.18.0 (Ubuntu)
- RespHeader Date: Mon, 12 Dec 2022 14:21:10 GMT
- RespHeader Content-Type: application/x-protobuf
- RespHeader Content-Length: 31578
- RespHeader Access-Control-Allow-Origin: *
- RespHeader Content-Encoding: gzip
- RespHeader Last-Modified: Wed, 23 Nov 2022 09:25:23 GMT
- RespHeader ETag: W/"7b5a-Lgi1EP0ZRDWVK1iX+VP47MXHk2M"
- RespHeader Expires: Wed, 14 Dec 2022 14:21:10 GMT
- RespHeader Cache-Control: max-age=172800, public, no-transform
- RespHeader Vary: Accept-Encoding
- RespHeader X-Varnish: 98350 98319
- RespHeader Age: 163
- RespHeader Via: 1.1 varnish (Varnish/6.6)
- VCL_call DELIVER
- RespHeader X-Cache: HIT
- VCL_return deliver
- Timestamp Process: 1670855034.759391 0.000089 0.000089
- Filters
- RespHeader Accept-Ranges: bytes
- RespHeader Connection: close
- Timestamp Resp: 1670855034.759479 0.000177 0.000087
- ReqAcct 555 0 555 531 31578 32109
- End