Log in value from Set-Cookie header in nginx

2019-05-17 20:30发布

问题:

Is it possible to write in nginx access log value of key 'uuid' from Cookie for server response (header: Set-Cookie)?

$cookie_uuid - return uuid that sent client $sent_http_set_cookie - return whole header Set-Cookie: 'uuid=897587e7-a733-422f-9daa-b3105a5895aa; domain=domain.com; path=/; expires=Tue, 09-Aug-2033 01:17:54 GMT', but I need save only value for key 'uuid'

Thanks

回答1:

map $sent_http_set_cookie $resp_uuid {
    ~*uuid=(?<u>[0-9a-f-]+) $u;
}

Reference:

  • http://nginx.org/r/map
  • man pcresyntax