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
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
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?
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.
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.
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.