cookies not being recongnized / regenerated after some time only on cloud VPS

Authentication in Laravel doesn’t work some time after the deploy in a specific environment

I have 2 web platforms built with Laravel that work perfectly fine both on the development environment as well as on local environemnt.

The problem lies in the fact that after I deploy these applications on a cloud infrastructure as a service provider, the applications work for approximatelly ~ 1 / 2 hours, sometimes even less, and then, on every login request it redirects me to back to the login page, even though the credentials on the login attempt are correct.

In between the login request and the redirect response I get blank view with the XSRF token stored in the session, but only for a few miliseconds.

For a clearer view of the problem I need to give you the full context so I will briefly document the infrastructure and the architecture on which the application runs

The applications use the following technologies:

  • Laravel (web platform built in the old fashioned monolith style) v10
  • MariaDB v10.7.5
  • Redis cache database v.6.2.7
  • Melisearch v0.27.2

For each one of these technologies there is a Docker container. The communication between them is facilitated by a traefik Docker network. (all containers are on the same droplet)

These are some of the environment configuration variables I use that I think might be relevant for the problem:

  • for one of the platforms are these:
  • for the other platfom are just the default ones:

💡 also for the second web platform I did’t configure the Redis and Melisearch services and I only run 2 Docker containers, for the app and database.


The following things can be done to temporarily get the app working:

  • ssh-ing into the VPS and manually restarting the container
  • clearing the 2 cookies from the browser’s storage (XSRF-cookie, applications session cookie

💡 Note that the develop environment, the one on which the web applications work with no problems is on a self-hosted and maintained server that also has a DNS, CDN and revers-proxy provider on top

Has someone else encountered this wierd behaviour? If so what’s causing it and how could it be solved?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel