Dotted cookie name as proxy_cache_key problem

Maxim Dounin mdounin at
Thu Mar 11 17:21:40 MSK 2010


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 Dounin

More information about the nginx mailing list