Varnish+Nginx+Magento cannot serve same page multiple times, resp 502

Varnish+Nginx+Magento cannot serve same page multiple times, resp 502

September 16, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Varnish+Nginx+Magento cannot serve same page multiple times, resp 502

The issue you’re facing seems to be related to how Varnish is caching the responses from your Magento store. Let’s break down the problem step by step.

Firstly, when a user browses the catalog or product pages, Varnish is correctly caching these responses and serving them from cache when subsequent requests are made. This significantly reduces the load on your Magento server and improves performance.

However, there seems to be an issue with how Varnish handles the cart functionality in Magento 2. When a user adds products to their cart or views the cart page, Varnish is not correctly updating its cached responses to reflect the changes in the cart data. This leads to the inconsistency you’re observing – the cart shows as empty when viewed directly but appears to be populated with items if accessed indirectly.

To troubleshoot this issue:

  1. Check your Varnish configuration: Ensure that the cache settings for the cart-related pages are configured correctly. Look for any specific rules or exceptions related to “cart” in your Varnish vcl file.

  2. Verify Magento 2’s cache handling: Make sure that Magento 2 is properly clearing its own cache when necessary, such as when a product is added or removed from the cart. Check if there are any relevant events or observers in your Magento codebase that handle this process.

  3. Analyze Varnish logs: Enable detailed logging for your Varnish instance and analyze the logs to see how it behaves when a user interacts with the cart functionality. Look for any errors, warnings, or unusual patterns related to cache invalidation or expiration.

  4. Check Nginx configuration: Ensure that the Nginx server is properly configured to handle requests from Varnish. Make sure there are no conflicting rules or settings in your Nginx configuration file.

  5. Inspect the response headers: Analyze the response headers sent by Varnish and Magento 2 when a user interacts with the cart. Check if any important cache-related headers, such as “Cache-Control” or “Expires”, are missing or incorrectly configured.

It’s important to note that this issue might not be solely related to your codebase but could also be caused by a misconfiguration in Varnish or Magento 2 itself. It is recommended to consult the documentation and seek assistance from the official support channels if needed.

In conclusion, the problem you’re facing seems to lie within the caching mechanism of Varnish or the interaction between Varnish and your Magento store’s cart functionality. By carefully examining your configuration files, logs, and response headers, you should be able to identify the root cause and find a solution that ensures proper cache invalidation for the cart-related pages.

Magento 2 Checkout Catalog Cache

Our network