sticky session nginx for limited time

56 views Asked by At

I'm trying to implement sticky sessions in Nginx for a limited time based on a cookie generated by a Python application. In the nginx.conf file, I know I can use ip_hash to ensure that I stay on the same server. However, I need to remain on the same server for only 1 minute before being directed to a different server.

1

There are 1 answers

1
LF-DevJourney On

Use the nginx sticky directive.

For example:

upstream backend {
    server backend1.example.com;
    server backend2.example.com;

    sticky cookie srv_id expires=1h domain=.example.com path=/;
}