Home
Support Forums

Proxy caching issues

I am having some very strange issues.
The Netlify proxy function seems to be caching the responses and not expiring them at random.
A few days ago the proxied endpoint served some 301 redirects. Since then we completely changed the endpoint and redeployed many times but Netlify is still serving them at random.
Basically some responses are 200 and correct and others are old 301.
And we can’t figure our how to purge the Netlify cache to get rid of the old 301 redirects.

Config:

[[redirects]]
  from = "/blog/*"
  to = "https://*/blog/:splat"
  status = 200
  force = true

Curls one after the other. Sometimes it takes a few seconds or minutes to hit the wrong redirect. Others it keeps hitting the redirect every few requests

# curl https://*.com/blog/ -I

HTTP/2 200
accept-ranges: bytes
age: 1750
cache-control: public
content-length: 10893
content-type: text/html; charset=UTF-8
date: Thu, 26 Dec 2019 12:32:11 GMT
referrer-policy: strict-origin-when-cross-origin
server: Netlify
strict-transport-security: max-age=15768000
vary: Accept-Encoding
x-nf-request-id: f69c62fb-8882-4ea0-b115-255dcbcb8f1b-10757663

# curl https://*.com/blog/ -I

HTTP/2 301
cache-control: public, max-age=31536000
content-length: 60
content-type: text/plain; charset=utf-8
date: Tue, 24 Dec 2019 22:02:49 GMT
location: https://*.com/blog/
server: Netlify
x-powered-by: Express
age: 140357
vary: Accept,Accept-Encoding
x-nf-request-id: a5cf0029-6f22-40ae-b49a-afd144f868f7-9041480

Some more queries one after the other:

[root@q ~]# curl -I https://*.com/blog/
HTTP/2 200
cache-control: public, max-age=0
content-length: 11621
content-type: text/html; charset=utf-8
date: Thu, 26 Dec 2019 20:05:01 GMT
etag: W/"2d65-zPuF1d90SF4mlEC9zeG3PF9xq9g"
server: Netlify
x-powered-by: Express
age: 0
vary: Accept-Encoding
x-nf-request-id: 1af5de27-4515-4c31-adfb-a8ad49c5637d-2632743

[root@q ~]# curl -I https://*.com/blog/
HTTP/2 200
cache-control: public, max-age=0
content-length: 11621
content-type: text/html; charset=utf-8
date: Thu, 26 Dec 2019 20:05:02 GMT
etag: W/"2d65-zPuF1d90SF4mlEC9zeG3PF9xq9g"
server: Netlify
x-powered-by: Express
age: 0
vary: Accept-Encoding
x-nf-request-id: 1af5de27-4515-4c31-adfb-a8ad49c5637d-2633125

[root@q ~]# curl -I https://*.com/blog/
HTTP/2 200
cache-control: public, max-age=0
content-length: 11621
content-type: text/html; charset=utf-8
date: Thu, 26 Dec 2019 20:05:03 GMT
etag: W/"2d65-zPuF1d90SF4mlEC9zeG3PF9xq9g"
server: Netlify
x-powered-by: Express
age: 1
vary: Accept-Encoding
x-nf-request-id: 1af5de27-4515-4c31-adfb-a8ad49c5637d-2633723

[root@q ~]# curl -I https://*.com/blog/
HTTP/2 301
cache-control: public, max-age=31536000
content-length: 60
content-type: text/plain; charset=utf-8
date: Tue, 24 Dec 2019 22:02:49 GMT
location: https://*.com/blog/
server: Netlify
x-powered-by: Express
age: 165734
vary: Accept,Accept-Encoding
x-nf-request-id: 9b965e6e-d769-450b-b4d9-5a7c82b28d72-4508582

[root@q ~]# curl -I https://*.com/blog/
HTTP/2 301
cache-control: public, max-age=31536000
content-length: 60
content-type: text/plain; charset=utf-8
date: Tue, 24 Dec 2019 22:02:49 GMT
location: https://*.com/blog/
server: Netlify
x-powered-by: Express
age: 165736
vary: Accept,Accept-Encoding
x-nf-request-id: 9b965e6e-d769-450b-b4d9-5a7c82b28d72-4509924

[root@q ~]# curl -I https://*.com/blog/
HTTP/2 301
cache-control: public, max-age=31536000
content-length: 60
content-type: text/plain; charset=utf-8
date: Tue, 24 Dec 2019 22:02:49 GMT
location: https://*.com/blog/
server: Netlify
x-powered-by: Express
age: 165737
vary: Accept,Accept-Encoding
x-nf-request-id: 9b965e6e-d769-450b-b4d9-5a7c82b28d72-4510193

I think its been 3+ days now and its continuing.

[root@q ~]# curl -I https://*.com/blog/
HTTP/2 301
cache-control: public, max-age=31536000
content-length: 60
content-type: text/plain; charset=utf-8
date: Tue, 24 Dec 2019 22:02:49 GMT
location: https://*.com/blog/
server: Netlify
x-powered-by: Express
age: 216671
vary: Accept,Accept-Encoding
x-nf-request-id: 9afa4167-b192-469b-91ff-571f91567d87-2740784

[root@q ~]# curl -I https://*.com/blog/
HTTP/2 301
cache-control: public, max-age=31536000
content-length: 60
content-type: text/plain; charset=utf-8
date: Tue, 24 Dec 2019 22:02:49 GMT
location: https://*.com/blog/
server: Netlify
x-powered-by: Express
age: 216671
vary: Accept,Accept-Encoding
x-nf-request-id: 9afa4167-b192-469b-91ff-571f91567d87-2741127

[root@q ~]# curl -I https://*.com/blog/
HTTP/2 200
cache-control: public, max-age=0
content-length: 11621
content-type: text/html; charset=utf-8
date: Fri, 27 Dec 2019 10:14:01 GMT
etag: W/"2d65-8ZtpPwA0MQMFsMeqGQpFjn2GOck"
server: Netlify
x-powered-by: Express
age: 0
vary: Accept-Encoding
x-nf-request-id: abec4116-b3df-4a58-92af-01216a809f5e-4076497

^[[A[root@q ~]# curl -I https://*.com/blog/
HTTP/2 200
cache-control: public, max-age=0
content-length: 11621
content-type: text/html; charset=utf-8
date: Fri, 27 Dec 2019 10:14:01 GMT
etag: W/"2d65-8ZtpPwA0MQMFsMeqGQpFjn2GOck"
server: Netlify
x-powered-by: Express
age: 0
vary: Accept-Encoding
x-nf-request-id: abec4116-b3df-4a58-92af-01216a809f5e-4076758

[root@q ~]# curl -I https://*.com/blog/
HTTP/2 301
cache-control: public, max-age=31536000
content-length: 60
content-type: text/plain; charset=utf-8
date: Tue, 24 Dec 2019 22:02:49 GMT
location: https://*.com/blog/
server: Netlify
x-powered-by: Express
age: 216673
vary: Accept,Accept-Encoding
x-nf-request-id: 9afa4167-b192-469b-91ff-571f91567d87-2742562

Hello @ack22, without knowing which domain you are referring to, there’s no way to know why you are seeing what you are seeing. Are you redirecting to a different site? Is that site also a netlify site or something hosted somewhere else?

I hoped the Netlify IDs would be enough. I can PM you the domain if you want.
As you can see in the config all I am doing is proxying a website under /blog that I personally host (a ghost blog). That site responds normally with 200. But 3-4 days ago it has bad 301 redirects that seem to have been cached by netlify and I see no way to expire them from your system

What do you think? This is impacting our production and not sure what to do

From what I can see, the 301 status is coming from the server that you are proxying to. If that happens, we just pass the response through, included the status. You’ll want to make sure your server is responding with what you are expecting.

Like I said before this is not true. We completely changed the endpoint to a different app which completely changed the headers to different ones and made it easy to see what backend netlify proxy is serving.
The backend was WordPress and responding with correct 200 headers, while Netlify was continuing serving at random node.js express 301 headers.
This means Netlify has cached 6day old 301 headers in some POPs and keeps serving them at random.

Please escalate so that someone could check the IDs of requests that show the issue.

After looking through our logs using the request-id’s you provided, it seems that what you are seeing is isolated to a specific node. Note that our nodes will cache proxied response based on the cache-control header. It seems like that node had cached that Express response because of the 1-year long cache-control header and since that node is not the only one in the region, you only see the issue intermittently.

That said, I did check for any cache inconsistencies but do not see any issues at this time. Regardless, I cleared the cache for your site from our end.

If you do see the issue again, please provide the actual URL that is seeing the issue so that we can help you more efficiently.

Thank you very much. So was that a bug of the node or just how your caching works?
And is there a way for us to force a cache purge to avoid similar issues in the future?

Thanks again

That’s just how our caching works. Our system respects the cache-control headers, so if you want to avoid running into these issues would be to have the proxied content send a cache-control header that is pretty short or no-cache.

Also, any time you trigger a deploy on your site, that also purges your site’s cache on our CDN.

You can use these 2 things to help you avoid similar issues in the future.

Well as I said above we tried deploying many times but it didn’t help. So your CDN didn’t purge the cached redirects and it looks like a bug

Seems to me that you have directed us to cache for a year - The browser itself will respect that caching directive, regardless of what we do.

This is why we recommend against setting cache control headers yourself:

I’d suggest picking a different path to use going forward, not using custom cache-control headers, and letting us know if you still see the problem and in that case it would definitely be a bug…

The blog platform set those headers automatically so it wasn’t on purpose. I am aware the browser will cache it so all tests were done using curl. I just assumed Netlify would purge them automatically on a deploy. Otherwise our website would simply be broken for a year until the redirects expire by themselves.

We removed cache-headers manually on origin for 301/302 later but Netlify continued serving the old cached redirects at random.

Our website is working now, but this seems like a problem we could run into again in the future and wanted to make sure there is a way to fix it if it happens again.

hey @ack22 - glad to hear that it is working now.

Following what we posted above is going to make things work more reliably - and if you should encounter any issues, feel free to circle back with us here. :+1: