I notice that when I set up to cache everything for large exe files(about 10MB). Then I will get 404 errors intermittently when downloading these files, though they are existing.
Could you grab and share a screenshot of this error?
Is it coming from your origin host / server or rather somehow from Cloudflare for the requested resource?
Now I am checking the system access log to see why 404 will occurs for existing file.
Anyway, you can see a sample URL at https://www.datanumen.com/downloads/files/doeu.exe , I have just enabled the “Origin Cache Control” for the file. But it seems the following cache-control rule still not work:
BTW: As far as I can remember, Cloudflare will always respect the origin cache control, see Default Cache Behavior · Cloudflare Cache (CDN) docs, so why bother to enable that option “Origin Cache Control” again?
Have you tried to manually purge the cache via the Cloudflare dashboard for a specific URL (https://www.datanumen.com/downloads/files/doeu.exe)?, Does this work?
Also, maybe to try purging both at APO plugin interface and also at Cloudflare dashboard - Purge Everything?
Yes, we are using APO plugin for WordPress. Also we are using Argo Tiered Cache as well.
And yes, if we purge the URL manually, then the issue will be solved. However, after sometimes, one or several files will have such a problem again. So, what we need is to solve the issue for ever, not just for now.
By default, Cloudflare will cache 404 for 3 mins. However, now I setup a rule:
Cache Everything
Set Edge TTL to 14 days.
Origin Cache Control: On
Then Cloudflare will cache everything, including 404 for 14 days in the edge server. To keep it continue caching 404 for 3 mins, while cache others for 14 days, I addded the following cache control headers:
Reacces the file. Since the file now exists, and it has passed the max-age(3min) for cdn-cache-control, so it should not return 404.
But the test results shows that URL will continue return 404, until I purge the cache for that URL manually in Cloudflare.
So it seems that the cache control headers does not work on Cloudflare at all? Even though I have enabled “Origin Cache Control: On”?
With the help of Cloudflare support, I am finally able to solve the issue.
In CDN-Cache-Control · Cloudflare Cache (CDN) docs, it said " The Edge Cache TTL page rule overrides the amount of time an asset is cached on the edge (Cloudflare data centers). This page rule overrides directives in Cloudflare-CDN-Cache-Control/CDN-Cache-Control which manage how long an asset is cached on the edge."
So, to set different edge TTL for normal objects and 404, we should do as follows:
Remove all Edge Cache TTL settings.
In .htaccess, add the following line:
# Set edge TTL to 14 days for normal objects
Header set CDN-Cache-Control "max-age=1209600"
Header set Cloudflare-CDN-Cache-Control "max-age=1209600"
# Set edge to not cache 404
Header set CDN-Cache-Control "no-cache, must-revalidate, max-age=0" "expr=%{REQUEST_STATUS} == 404"
Header set Cloudflare-CDN-Cache-Control "no-cache, must-revalidate, max-age=0" "expr=%{REQUEST_STATUS} == 404"
After that, the edge will cache normal objects for 14 days and not cache 404, working as expected.