apache How to use “Header set Set-Cookie expires=<date>” dynamically

痞子三分冷 提交于 2019-12-23 07:11:24

问题


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!


回答1:


Maybe you could keep your idea with a generic rule

RewriteCond %{HTTP_COOKIE} h=\.([1-8]) [NC]
RewriteRule . - [CO=h:.%1:.domain.com:30:/]



回答2:


I looked at the paypal sites cookie and found they set the cookie time to past year -(01 -01-1970). The reason behind this could be to stop reuse of cookies.



来源:https://stackoverflow.com/questions/29549963/apache-how-to-use-header-set-set-cookie-expires-date-dynamically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!