I am using apache as a load balancer and reverse proxy. For session stickiness I am creating a cookie with the route of the node.
Header set Set-Cookie "h=.%{BALANCER_WORKER_ROUTE}e; path=/; domain=.domain.com" env=BALANCER_ROUTE_CHANGED
How do I set the expires
value in the cookie to be X minutes from when the request comes in?
The documentation for mod_headers Doesn't even cover Set-Cookie
in detail so there is no info there on a dynamic syntax to use for expires
.
I tried setting the max-age
but unfortunatelly max-age doesn't work with IE 11 and lots of our customers use it.
The docs for mod_rewrite cookie do cover how to set a lifetime in the cookie so I can get it to work using this ugly mod_rewrite hack but I had to do one rule per route since it didn't work inside my <Proxy balancer://my_cluster>
section:
RewriteCond %{HTTP_COOKIE} h=.1 [NC]
RewriteRule . - [CO=h:.1:.domain.com:30:/]
RewriteCond %{HTTP_COOKIE} h=.2 [NC]
RewriteRule . - [CO=h:.2:.domain.com:30:/]
RewriteCond %{HTTP_COOKIE} h=.3 [NC]
RewriteRule . - [CO=h:.3:.domain.com:30:/]
RewriteCond %{HTTP_COOKIE} h=.4 [NC]
RewriteRule . - [CO=h:.4:.domain.com:30:/]
RewriteCond %{HTTP_COOKIE} h=.5 [NC]
RewriteRule . - [CO=h:.5:.domain.com:30:/]
RewriteCond %{HTTP_COOKIE} h=.6 [NC]
RewriteRule . - [CO=h:.6:.domain.com:30:/]
RewriteCond %{HTTP_COOKIE} h=.7 [NC]
RewriteRule . - [CO=h:.7:.domain.com:30:/]
RewriteCond %{HTTP_COOKIE} h=.8 [NC]
RewriteRule . - [CO=h:.8:.domain.com:30:/]
Any ideas on how to accomplish with Header set Set-Cookie
? Thanks!
Maybe you could keep your idea with a generic rule
RewriteCond %{HTTP_COOKIE} h=\.([1-8]) [NC]
RewriteRule . - [CO=h:.%1:.domain.com:30:/]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With