HAProxy community

How to set cookie expiration date



I’m new to HAProxy and need some help to configure the cookie expiration date, all information I find online is either from old versions or doesn’t match my configuration. See below my current configuration. Any advise would be appreciated. Thx!

frontend http_front
bind :80
bind :443
maxconn 20000
stats uri /haproxy?stats
default_backend http_back

backend http_back
mode http
balance roundrobin
option forwardfor
cookie MyCookieName insert indirect nocache
server Server1 .server1.mydomain.com:80 weight 5 check cookie CookieName
server Server2 server2.mydomain.com:443 weight 95 check ssl verify none cookie MyCookieName



It should be just like this:

cookie MyCookieName maxidle 30m maxlife 12h insert nocache indirect


Thank you @AaronWest! Just configured it like that, but the cookie expiration date still shows “1969-12-31T23:59:59.000Z” in Google Chrome. Any thoughts?


Yes you are right!

In Chrome it shows the date and time as you suggest but it seems to be fine in Firefox… I’m thinking it’s a Chrome bug, I hope only a display one but guess we can test with a short maxlife.


Scratch that, I misread Firefox, they both just have a session cookie…


Okay so I’m being stupid… Stupid because I now remember doing this before!!

So let’s clear this one up… You have 2 types of cookie, session cookies and persistent cookies, persistent cookies get written to disk I think while session cookies can live only up to when you close the browser.

HAProxy uses session cookies but it can set the maxlife and maxidle value of these cookies.

When you provide no maxlife or maxidle the “Value” of the cookie will just be “ServerName”, however, when you enable a setting such as maxlife you will see the value change to “ServerName|W/Ndy|W/Ndv”.

The extra characters are the timers added to the cookie which will count down accordingly.

I hope that helps make it clearer and I hope it helps me remember this again for next time too!


No, you are right! In Chrome it shows 1969 in expiration date while “session” in Chrome…but I still don’t understand why I can’t set a specific date or time frame instead of “session”…


So, how would you set a date? By changing the cookies’s name?? “ServerName|W/Ndy|W/Ndv”


To have an expires on date you would need to use a different type of cookie which HAProxy doesn’t do, a persistent cookie.

The reason Chrome shows 1969 is this is just what it does with some session cookies while for me Firefox correctly shows it as type “session”.

The maxlife and maxidle values are being encoded along with the cookie value. Check in your browser with and without the maxlife/maxidle being set, if you have neither the value will just be “ServerName” but if you provide a maxlife it’ll be “ServerName + Encoded time values”.

Here is someone else who had the same confusion we just have: