I am working on a webshop, where the cart is stored in a session. I noticed that after a certain amount of distinct items added to the cart, I start receiving 502-responses, when I want to add more (distinct items). I am using Laravel and the site is hosted via Laravel Forge (using Nginx). I am using cookies to store the sessions.
.env
SESSION_DRIVER=cookie
I found lots of suggested solutions, but none of them worked for me.
I have meanwhile found the solution to this problem (see answer below). I am asking this question not because I need help, but because I want to help others who struggle with this issue, since it cost me a lot of time.
Asking questions just to answer them yourself is actively encouraged according to this blogpost by one of StackOverflow's co-founders: https://stackoverflow.blog/2011/07/01/its-ok-to-ask-and-answer-your-own-questions/.
The fix for my problem was to choose a different session driver. The problem seems to be connected to the limitations of cookies as implemented by browsers: https://github.com/laravel/framework/issues/18112
So I switched to using files to store sessions.
.env
SESSION_DRIVER=file
But this did not work right away. It only started working after I ssh-ed into the server and ran these commands:
composer dump-autoload
php artisan config:clear
php artisan cache:clear
(Also, I cleared all cookies stored for this site in my browser.)