I'm using Varnish on my Magento 2.4.1.

I've enabled Cloudlfare now, it works well but when I do some changes on the backend (like adding text on category pages, etc), it is not reflecting on the frontend anymore => I have to clear Varnish cache completely to make the changes appear.

I've asked my hosting company to apply this: https://support.cloudflare.com/hc/en-us/articles/200169376-Can-I-use-Cloudflare-and-Varnish-together-

They did but that doesn't make any difference.

Is it possible to make Varnish & Cloudflare to work together on M2 ?

Many thanks !


What are your configuration for cloudflare? Any special settings? Have you modiefied cloudflare to cache html? (its not standard)

from cloudflare documentation:

Cloudflare does not cache HTML resources automatically. This prevents us from unintentionally caching pages that often contain dynamic elements. For example, the content on certain HTML pages may change based on specific visitor characteristics, such as authentication, personalization, and shopping cart information.

In your setup with cloudflare and varnish i recommend using cloudflare für picture, js, css, etc. (the standard) and varnish for the html. This way M2 only have to invalidate varnish.

We are using also cloudflare and varnish with M2 and are quite happy with that setup, that i described. We have only defined some page rules for admin (bypass) and /wysiwyg/.thumbs/ (Ignore Query String) for better usability in the backend.

  • Hi, thanks for your reply. On Cloudflare, I have a pro plan, but nothing special configured here. – Jack Feb 15 at 14:18
  • I've enabled basic features, have no rule to cache html – Jack Feb 15 at 14:20
  • Problem is since Cloudflare is ON, Varnish doesn't invalidate the cache anymore - of there is a conflict with IP, I don't know. Did you do something to restore real IP, or something ? – Jack Feb 15 at 14:24
  • this is strange, is it possible that this is an issue with how you communicate with varnish (cloudflare shouldn't interfere with that)? what are the settings there (env.php)? are you using names or public ip's for http_cache_hosts? and also use internal ip's in acl purge directive in varnish. not sure what your setup is.. – moonhawk Feb 15 at 15:47
  • hum, would it be possible to share your Varnish configuration here or in private ? I guess I should have something wrongly set here, but I'm not so familiar with these hosting configuration... – Jack Feb 15 at 17:16

There is a bug report here which seems to be closed at the moment: https://github.com/magento/magento2/issues/5980

I agree with @moonhawk comment that cloudflare won't be the problem. Instead, you might be experiencing that github issue as many other people (including me).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.