Skip to content

Product view – Varnish – add to cart link gives error 404

Recently I have started getting an error 404 for add to cart link:

/checkout/cart/add/uenc/…../product/1432/

when clicked in product view page. In category view all is fine. It seems like it is related to varnish cache as when I switch back to built in cache: redis, everything is fine.
When checking log using: varnishlog -q ‘ReqURL ~ “/checkout/cart/add/uenc/”‘

*   << Request  >> 1046027   
-   Begin          req 1046026 rxreq
-   Timestamp      Start: 1668344268.973650 0.000000 0.000000
-   Timestamp      Req: 1668344268.973650 0.000000 0.000000
-   VCL_use        boot
-   ReqStart       127.0.0.1 39790 a0
-   ReqMethod      GET
-   ReqURL         /checkout/cart/add/uenc/aHR0cHM6Ly96b3J6ZWNob3dvb3d5LWJpby00N2c/product/2488/
-   ReqProtocol    HTTP/1.1
-   ReqHeader      Host: domain.com
-   ReqHeader      X-Forwarded-Host: domain.com
-   ReqHeader      X-Real-IP: X.X.X.X
-   ReqHeader      X-Forwarded-For: X.X.X.X
-   ReqHeader      Ssl-Offloaded: 1
-   ReqHeader      X-Forwarded-Proto: https
-   ReqHeader      X-Forwarded-Port: 443
-   ReqHeader      Connection: close
-   ReqHeader      sec-ch-ua: "Google Chrome";v="107", "Chromium";v="107", "Not=A?Brand";v="24"
-   ReqHeader      Accept: application/json, text/javascript, */*; q=0.01
-   ReqHeader      X-Requested-With: XMLHttpRequest
-   ReqHeader      sec-ch-ua-mobile: ?1
-   ReqHeader      User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Mobile Safari/537.36
-   ReqHeader      sec-ch-ua-platform: "Android"
-   ReqHeader      Sec-Fetch-Site: same-origin
-   ReqHeader      Sec-Fetch-Mode: cors
-   ReqHeader      Sec-Fetch-Dest: empty
-   ReqHeader      Referer: https://domain.com/product-page
-   ReqHeader      Accept-Encoding: gzip, deflate, br
-   ReqHeader      Accept-Language: pl-PL,pl;q=0.9
-   ReqHeader      Cookie: form_key=6QeOlabVUpfd3blu; mage-cache-storage={}; mage-cache-storage-section-invalidation={}; mage-messages=; PHPZSSESSID=vt3v47d8np7r5cghqhkp8; form_key=6QeUpfd3blu; cookie_consent=%7B%22groups%22%
-   ReqUnset       X-Forwarded-For: X.X.X.X
-   ReqHeader      X-Forwarded-For: X.X.X.X, 127.0.0.1
-   VCL_call       RECV
-   ReqHeader      X-brotli: true
-   ReqUnset       Host: domain.com
-   ReqHeader      Host: domain.com
-   ReqURL         /checkout/cart/add/uenc/aHR0cHM6Ly96b3J6ZWNob3dvb3d5LWJpby00N2c/product/2488/
-   VCL_return     pass
-   VCL_call       HASH
-   VCL_return     lookup
-   VCL_call       PASS
-   VCL_return     fetch
-   Link           bereq 1046028 pass
-   Timestamp      Fetch: 1668344269.861477 0.887827 0.887827
-   RespProtocol   HTTP/1.1
-   RespStatus     404
-   RespReason     Not Found
-   RespHeader     Server: nginx
-   RespHeader     Date: Sun, 13 Nov 2022 12:57:49 GMT
-   RespHeader     Content-Type: text/html; charset=UTF-8
-   RespHeader     Vary: Accept-Encoding
-   RespHeader     Last-Modified: Wed, 26 Oct 2022 22:15:05 GMT
-   RespHeader     Set-Cookie: form_key=6QeOlabVUpfd3blu; expires=Sun, 20-Nov-2022 12:57:49 GMT; Max-Age=604800; path=/; domain=domain.com; secure; SameSite=Lax
-   RespHeader     Pragma: cache
-   RespHeader     Expires: Tue, 13 Dec 2022 12:57:49 GMT
-   RespHeader     Cache-Control: max-age=0, must-revalidate, no-cache, no-store
-   RespHeader     X-Magento-Tags: store,cms_b,gdpr_c,theme_editor_backend_css_block,cms_b_header_cms_links,cms_b_argento_scroll_up,cms_b_footer_cms_content,cms_b_13,placeholder__4,placeholder__5,placeholder__6,placeholder__7,placeholder__8,placeholder__9,placeholder__10,p
-   RespHeader     X-DNS-Prefetch-Control: on
-   RespHeader     Link: <https://domain.com/media/logo/default/logo_c.svg>; rel=preload; as=image, <https://domain.com/static/version1668205146/_cache/merged/c217df33faa001faacedbd09307a93e4.min.js>; rel=preload; as=script
-   RespHeader     Report-To: {"group":"report-endpoint","max_age":10886400,"endpoints":[{"url":"https://domain.report-uri.com/r/d/csp/reportOnly/"}]}
-   RespHeader     Content-Security-Policy-Report-Only: font-src *.fontawesome.com maxcdn.bootstrapcdn.com fonts.gstatic.com https://geowidget.easypack24.net *.cloudflare.com *.twitter.com *.gstatic.com *.googleapis.com *.bootstrapcdn.com 'self' data: domain.com
-   RespHeader     X-Content-Type-Options: nosniff
-   RespHeader     X-XSS-Protection: 1; mode=block
-   RespHeader     X-Frame-Options: SAMEORIGIN
-   RespHeader     Content-Encoding: gzip
-   RespHeader     X-Varnish: 1046027
-   RespHeader     Age: 0
-   RespHeader     Via: 1.1 varnish (Varnish/7.0)
-   VCL_call       DELIVER
-   RespUnset      Age: 0
-   RespUnset      Pragma: cache
-   RespHeader     Pragma: no-cache
-   RespUnset      Expires: Tue, 13 Dec 2022 12:57:49 GMT
-   RespHeader     Expires: -1
-   RespUnset      Cache-Control: max-age=0, must-revalidate, no-cache, no-store
-   RespHeader     Cache-Control: no-store, no-cache, must-revalidate, max-age=0
-   RespUnset      X-Magento-Tags: store,cms_b,gdpr_c,theme_editor_backend_css_block,cms_b_header_cms_links,cms_b_argento_scroll_up,cms_b_footer_cms_content,cms_b_13,placeholder__4,placeholder__5,placeholder__6,placeholder__7,placeholder__8,placeholder__9,placeholder__10,p
-   RespUnset      Server: nginx
-   RespUnset      X-Varnish: 1046027
-   RespUnset      Via: 1.1 varnish (Varnish/7.0)
-   RespUnset      Link: <https://domain.com/media/logo/default/logo_c.svg>; rel=preload; as=image, <https://domain.com/static/version1668205146/_cache/merged/c217df33faa001faacedbd09307a93e4.min.js>; rel=preload; as=script
-   VCL_return     deliver
-   Timestamp      Process: 1668344269.861528 0.887878 0.000050
-   Filters         esi
-   RespHeader     Connection: close
-   RespHeader     Transfer-Encoding: chunked
-   Link           req 1046029 esi
-   Timestamp      Resp: 1668344269.863635 0.889985 0.002107
-   ReqAcct        1856 0 1856 6280 171354 177634
-   End            

And when I check link locally, using curl:

curl -I
http://127.0.0.1:8080/checkout/cart/add/uenc/aHR0cHM6Ly96b3J6ZWNob3dvb3d5LWJpby00N2c/product/2488/
I receive HTTP/1.1 302 Found redirection to https…

I use customized varnish config but an issue is still there when default varnish config is in use and most often mobile view in chrome is affected.
I don’t know exactly when this error did start showing up, so I can’t find a root cause. Any ideas?