Why was my Magento 2 website serving stale content and not syncing static files or product data correctly?

This issue was caused by a misconfiguration in the Varnish cache integration settings in env.php. Specifically, the 'http_cache_hosts' section had incorrect port numbers and host values, preventing Magento from properly purging cached content after updates.

The http_cache_hosts array in env.php tells Magento which Varnish servers to send purge requests to when content is updated. If the port or host is incorrect, Varnish won’t receive the purge request, and users will continue seeing outdated content.

Example of incorrect config:

'http_cache_hosts' => [
    ['host' => 's.com', 'port' => '8080'],
    ['host' => 'magento.com', 'port' => '8080']
],

updated the env.php file with the correct Varnish host and port that my server uses. In my case, Varnish was running on 127.0.0.1 using port 80, so I changed the configuration to:

'http_cache_hosts' => [
    ['host' => '127.0.0.1', 'port' => '80']
],

After the update, cleared the Magento cache and redeployed static content:

php bin/magento cache:flush
php bin/magento setup:static-content:deploy -f
php bin/magento indexer:reindex

Leave a comment

Your email address will not be published. Required fields are marked *