Cannot log a cookie with a dash in the name

Ruslan Ermilov ru at
Mon Mar 12 20:40:56 UTC 2012

On Mon, Mar 12, 2012 at 02:38:08PM -0400, Hates_ wrote:
> I am trying to log cookies but they have a dash in the name as such:
>     "Member-v1.0=$cookie_Member-v1.0"
> My logs come through as:
>     Member-v1.0=--v1.0
> Is there a work around?
> I've tried wrapping the name in curly brackets and also using
> underscores but get an error about an unmatched bracket or no value.
> I've tried the following formats:
>     "Member-v1.0=${cookie_Member-v1.0}"
>     "Member-v1.0=$cookie_Member_v1.0"
>     "Member-v1.0=$cookie_Member_v1_0"
> Any help would be greatly appreciated. I don't want to have to move to
> Apache :\

Currently, the names of nginx variables can be composed from
upper and lower English letters, digits and underscores.  The
dash and dot characters are thus invalid.

Without patching the code, you should be able to log the entire
value of the "Cookie" request header field with the $http_cookie
variable.  It can also be useful if you have cookies whose names
only differ in case as $cookie_<name> doesn't differentiate
between upper and lower case:

http {
    server {
        location / {
	    return 200 'http_cookie=$http_cookie cookie_a=$cookie_a cookie_A=$cookie_A\n';

$ curl -b 'a=a;A=A' http://localhost:8000/test
http_cookie=a=a;A=A cookie_a=a cookie_A=a

More information about the nginx mailing list