Module ngx_http_userid_module

Example Configuration
Directives
     userid
     userid_domain
     userid_expires
     userid_flags
     userid_mark
     userid_name
     userid_p3p
     userid_path
     userid_service
Embedded Variables

The ngx_http_userid_module module sets cookies suitable for client identification. Received and set cookies can be logged using the embedded variables $uid_got and $uid_set. This module is compatible with the mod_uid module for Apache.

Example Configuration

userid         on;
userid_name    uid;
userid_domain  example.com;
userid_path    /;
userid_expires 365d;
userid_p3p     'policyref="/w3c/p3p.xml", CP="CUR ADM OUR NOR STA NID"';

Directives

Syntax: userid on | v1 | log | off;
Default:
userid off;
Context: http, server, location

Enables or disables setting cookies and logging the received cookies:

on
enables the setting of version 2 cookies and logging of the received cookies;
v1
enables the setting of version 1 cookies and logging of the received cookies;
log
disables the setting of cookies, but enables logging of the received cookies;
off
disables the setting of cookies and logging of the received cookies.

Syntax: userid_domain name | none;
Default:
userid_domain none;
Context: http, server, location

Defines a domain for which the cookie is set. The none parameter disables setting of a domain for the cookie.

Syntax: userid_expires time | max | off;
Default:
userid_expires off;
Context: http, server, location

Sets a time during which a browser should keep the cookie. The parameter max will cause the cookie to expire on “31 Dec 2037 23:55:55 GMT”. The parameter off will cause the cookie to expire at the end of a browser session.

语法: userid_flags off | flag ...;
默认值:
userid_flags off;
上下文: http, server, location

此指令出现在版本 1.19.3 中。

如果参数不是 off,则为 Cookie 定义一个或多个附加标志:securehttponlysamesite=strictsamesite=laxsamesite=none

语法: userid_mark letter | digit | = | off;
默认值:
userid_mark off;
上下文: http, server, location

如果参数不是 off,则启用 Cookie 标记机制并设置用作标记的字符。此机制用于添加或更改 userid_p3p 和/或 Cookie 过期时间,同时保留客户端标识符。标记可以是英文字母(区分大小写)、数字或“=”字符中的任何一个。

如果设置了标记,则将其与传递给 Cookie 中的客户端标识符的 base64 表示中的第一个填充符进行比较。如果它们不匹配,则使用指定的标记、过期时间和“P3P”标头重新发送 Cookie。

语法: userid_name name;
默认值:
userid_name uid;
上下文: http, server, location

设置 Cookie 名称。

语法: userid_p3p string | none;
默认值:
userid_p3p none;
上下文: http, server, location

设置将与 Cookie 一起发送的“P3P”标头字段的值。如果指令设置为特殊值 none,则不会在响应中发送“P3P”标头。

语法: userid_path path;
默认值:
userid_path /;
上下文: http, server, location

定义设置 Cookie 的路径。

语法: userid_service number;
默认值:
userid_service 服务器的 IP 地址;
上下文: http, server, location

如果标识符由多个服务器(服务)发出,则应为每个服务分配其自己的编号,以确保客户端标识符是唯一的。对于版本 1 的 cookie,默认值为零。对于版本 2 的 cookie,默认值是服务器 IP 地址的最后四个八位组成的数字。

嵌入式变量

ngx_http_userid_module 模块支持以下嵌入式变量:

$uid_got
Cookie 名称和接收到的客户端标识符。
$uid_reset
如果变量设置为非空字符串且不是“0”,则客户端标识符将被重置。“log” 特殊值还会导致有关重置标识符的消息输出到 error_log
$uid_set
Cookie 名称和发送的客户端标识符。