Always online feature

My servers were down for 15 minutes today. During this time the “Always Online” feature did not worked. Users were getting some 502 error. I had transferred my DNS to Cloudflare about 2 years back. Proxy is also used

This is a major concern. Is it due to last week outage on Cloudflare

https://developers.cloudflare.com/cache/best-practices/always-online/

Always Online does not trigger for HTTP response codes such as 404, 503, or 500 errors such as database connection errors or internal server errors.

It’s meant for when your server itself is offline, not when your website is having database/internal errors.

In this case my server was offline

You can try to use serve Stale Cache when your server responds with errors along with a cache everything rule in the page rules. It worked better for me than the always online mode.

This way your (not logged in) visitors will be able to access your site while you fix the possible problem or perform maintenance. Areas like comments, forms, carts and log-in will still respond with errors, because in these cases your server needs to be contacted directly and you should create a rule for Cloudflare not to cache these important pages. In my case, I have a rule that tells Cloudflare not to cache dynamic pages from the Wordpress admin areas, but it can still serve static resources.

You just need to set the response header of your static assets with Cloudflare-CDN-Cache-Control max-age=seconds, stale-if-error=seconds and also set it for your static pages or posts.

For example you can set the header of your css and js files with something like:

Cloudflare-CDN-Cache-Control max-age=7889400, stale-if-error=604800

This will make Cloudflare serve your css and js files for 1 day (604800 seconds), in case your server responds with errors when someone visits your site. And you can set something like:

Cloudflare-CDN-Cache-Control max-age=2419200, stale-if-error=7200

For your static pages.

Just don’t forget to disable the Always Online mode in your account, because if it is enabled, Cloudflare will ignore the “stale-if-error” directive.

For more information you can check out a Cloudflare post on the subject and also the documentation for the cache response headers.

I can’t place links now, so if you want, you can search for “There’s Always Cache in the Banana Stand” at Cloudflare’s blog and “CDN Cache Control” at the Cloudflare Docs.

Regards.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.