cancel
Showing results for 
Search instead for 
Did you mean: 

First session add to cart action empties cart / clears session

First session add to cart action empties cart / clears session

I'm running an Nginx sandwiched Varnish backed magento 2.3.6 shop in development mode, set up like:

 

Frontend nginx port 443, varnish port 80, backend nginx port 8080, plus redis for session cache.

 

Nothing strange, fairly common setup.

 

Been developing my shop without varnish, but now after enabling varnish it seems that when I start my site with a clean magento cache, clean redis, clean varnish, and visit my site, add a product to the basket, after ~2 seconds I can see the cart being emptied.

 

After reading the entire internet, I'm at a loss. Disabling Varnish fixes this issue. Disabling Redis does not.

 

I've discovered that in my session storage ALL _session_validator_data have a remote_addr of 127.0.0.1, which seems wrong. Also the x-forwarded-for value is empty in all sessions.

 

By the way: After the first occurence, it does not happen again. When I enter production mode, it also doesn't happen.

 

Anyone has some pointers on the fix? Or some pointers on the troubleshooting? I've been looking for some 'advised' setup with Nginx SSL offloading in combination with Varnish, but the ones I can easily find on the interwebs seem to do the same as I'm doing....

 

thx in advance.

 

1 REPLY 1

Re: First session add to cart action empties cart / clears session

To whom it is of interest: the issue arose when the varnish configuration's [Static files caching] part was set like suggested for 'caching static files when you don't have a CDN'. Apparently this, in combination with magento developer mode (production didn't have the issue) caused the first visits on session sensitive pages (account, checkout, cart etc) to reset the user session, and with that emptying an existing cart's content.