原创文章,转载请指明出处并保留原文url地址
本文主要针对nginx的ngx_http_userid_module模块做简单介绍,本文具体包括如下指令:userid,userid_domain,userid_expires,userid_mark,userid_name,userid_p3p,userid_path,userid_service
ngx_http_userid_module模块为标示客户端设置合适的cookies。接受和设置的cookies能通过内嵌$uid_got 和 $uid_set变量获取,并记录到日志中。这个模块同apache的 mod_uid 模块不兼容。
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"';
Nginx原文:
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"';
1. userid
syntax: | userid on | v1 | log | off; |
default: | userid off; |
context: | http, server, location |
允许或禁止设置并且记录日志接受到的cookies
On
允许设置接受到cookies的版本2的cookies并记录日志
V1
允许设置接受到cookies的版本1的cookies并记录日志
Log
禁止设置cookies但是允许记录到日志中
Off
禁止设置并记录日志接受到cookies
Nginx原文:
Allows or prohibits to set cookies and log the received cookies:
on
allows to set version 2 cookies and log the received cookies;
v1
allows to set version 1 cookies and log the received cookies;
log
prohibits to set cookies but allows to log the received cookies;
off
prohibits to set cookies and log the received cookies.
2. userid_domain
syntax: | userid_domain name| none; |
default: | userid_domain none; |
context: | http, server, location |
定义要设置的cookies的域名。参数none禁止设置cookies的域名。
Nginx原文:
Defines a domain for which the cookie is set. The parameter none disables setting a domain for a cookie.
3. userid_expires
syntax: | userid_expires time| max | off; |
default: | userid_expires off; |
context: | http, server, location |
设置浏览器应该保留这个cookie的过期时间。这个max参数使cookie在“31 Dec 2037 23:55:55 GMT”年过期。这个最大的时间被旧的浏览器理解。Off参数使浏览器在session过期后让cookie过期。
Nginx原文:
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”. This is the maximum time understood by old browsers. The parameter off will cause the cookie to expire at the end of a browser session.
4. userid_mark
syntax: | userid_mark letter| digit | = | off; |
default: | userid_mark off; |
context: | http, server, location |
如果参数不是off,使能cookie的标志功能, 设置一个字符作为标志。这个机制运行添加或者改变userid_p3p或者cookie的过期时间,当保留客户端标志时。标记能是任何英文字母(大小写敏感),数字,或“=”字。
如果一个标记被设置,它将同在cookie中的客户端标示符base64 表示的第一个填充符号进行比较。如果他们不匹配,cookie被从新发送带有标志,过期时间和一个“P3P”头。
Nginx原文:
If parameter is not off, enables the cookie marking mechanism and sets a character used as a mark. This mechanism allows to add or change userid_p3p and/or cookie expiration time while preserving the client identifier. The mark can be any letter of the English alphabet (case-sensitive), digit, or the “=” character.
If a mark is set, it is compared with the first padding symbol in the base64 representation of client identifier passed in a cookie. If they do not match, a cookie is resent with the specified mark, expiration time and a “P3P” header.
5. userid_name
syntax: | userid_name name; |
default: | userid_name uid; |
context: | http, server, location |
设置cookie名称
Nginx原文:
Sets a cookie name.
6. userid_p3p
syntax: | userid_p3p string| none; |
default: | userid_p3p none; |
context: | http, server, location |
为随着cookie一起发送的“P3P”头部域设置一个值。如果特殊值none被设置则p3p头部域将不会被发送。
Nginx原文:
Sets a value for the “P3P” header field that will be sent along with a cookie. If set to the special value none, the “P3P” header will not be sent in a response.
7. userid_path
syntax: | userid_path path; |
default: | userid_path /; |
context: | http, server, location |
为设置的cookie设置一个路径
Nginx原文:
Defines a path for which the cookie is set.
8. userid_service
syntax: | userid_service number; |
default: | userid_service IP address of the server; |
context: | http, server, location |
如果标识符是由多个服务器发布(服务),每个服务器程序应该关联他自己的数字来确保客户标识符是唯一指定号码。对于版本1的cookie默认值为零的饼干。版本2cookie默认值组成从服务器ip地址最后4个字节中数字组成。
Nginx原文:
If identifiers are issued by multiple servers (services), each service should be assigned its own number in order to ensure that client identifiers are unique. For version 1 cookies the default value is zero. For version 2 cookies this is the number composed from the last four octets of the server’s IP address.
Embedded variables(内嵌变量)
ngx_http_userid_module模块应该支持下面内置的变量。
The ngx_http_userid_module module supports the following embedded variables:
$uid_got
The cookie name and received client identifier.
Cookie名称和接受到客户端标识。
$uid_reset
如果设置为非空字符串,并且他不是“0”,则客户端标识被重置(reset,从新设置)。特殊值log设置输出消息关于重置标识消息到error_log日志。
If set to a non-empty string, and it is not “0”, client identifiers are reset. The special value “log” additionally leads to the output of messages about reset identifiers to the error_log.
$uid_set
The cookie name and sent client identifier.
Cookie名称和发送客户端标识