I’m trying to configure proxy cache for backend server and cookie name
with user’s login is long with dots
(jetbrains.charisma.main.security.PRINCIPAL).
So my config is:
proxy_cache_key “$host$request_uri
$cookie_jetbrains.charisma.main.security.PRINCIPAL”;
And now proxied key is:
KEY: youtrack.jetbrains.net/issue/RSRP-170140
.charisma.main.security.PRINCIPAL
I think there’s some problem with parsing cookie name, because I don’t
see content of cookie in key name.
Nginx version is: 0.7.64
Can somebody explain me what should I set in proxy_cache_key to handle
cookie name correctly, please ?
Thanks,
Sergey
Posted at Nginx Forum:
Hello!
On Wed, Mar 10, 2010 at 10:59:53PM -0500, SergeyZh wrote:
I’m trying to configure proxy cache for backend server and
cookie name with user’s login is long with dots
(jetbrains.charisma.main.security.PRINCIPAL).
So my config is:
proxy_cache_key “$host$request_uri $cookie_jetbrains.charisma.main.security.PRINCIPAL”;
Try this:
- proxy_cache_key “$host$request_uri
$cookie_jetbrains.charisma.main.security.PRINCIPAL”;
- proxy_cache_key “$host$request_uri
${cookie_jetbrains.charisma.main.security.PRINCIPAL}”;
Maxim D.
I’ve tried this already, but there’s config error:
: the closing bracket in “cookie_jetbrains” variable is missing in
/usr/local/nginx/conf/nginx.conf:178
Also I’ve tried:
proxy_cache_key “$host$request_uri
$cookie_jetbrains.charisma.main.security.PRINCIPAL”;
and with \ and \\ before dot, without success.
There no error, but no success too.
Thanks,
Sergey
Posted at Nginx Forum:
Thanks a lot Maxim!
I’ve changed
(^|[;,])jetbrains.charisma.main.security.PRINCIPAL=([^;,]+)($|[;,])
to
(.*)jetbrains.charisma.main.security.PRINCIPAL=([^;,]+)($|[;,])
because your regexp didn’t matched my cookie and now everything is
working.
How cpu expensive these calculations ? Should I try to patch Nginx to
allow dot’s in cookie name or I can use this solution without any
overhead ?
Thanks,
Sergey
Posted at Nginx Forum:
Hello!
On Thu, Mar 11, 2010 at 08:30:12AM -0500, SergeyZh wrote:
I’ve tried this already, but there’s config error:
: the closing bracket in “cookie_jetbrains” variable is missing in /usr/local/nginx/conf/nginx.conf:178
Also I’ve tried:
proxy_cache_key “$host$request_uri $cookie_jetbrains.charisma.main.security.PRINCIPAL”;
and with \ and \\ before dot, without success.
There no error, but no success too.
Ah, indeed. nginx doesn’t allow anything but [A-Za-z0-9_] in
variable names, and it’s basically impossible to extract cookie
with other chars in it’s name via $cookie_* variables.
The only solution I see is to parse cookie header manually, e.g.
by something like this:
server {
…
proxy_cache_key "$host$request_uri $xx";
set $xx "";
if ($http_cookie ~
“(^|[;,])jetbrains.charisma.main.security.PRINCIPAL=([^;,]+)($|[;,])”)
{
set $xx $2;
}
...
}
Maxim D.