ngx_http_userid_module 模組
範例配置 指令 userid userid_domain userid_expires userid_flags userid_mark userid_name userid_p3p userid_path userid_service 嵌入變數 |
ngx_http_userid_module
模組設定適用於客戶端識別的 Cookie。可以使用嵌入變數 $uid_got 和 $uid_set 記錄接收和設定的 Cookie。此模組與 Apache 的 mod_uid 模組相容。
範例配置
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"';
指令
語法 |
userid |
---|---|
預設值 |
userid off; |
上下文 |
http , server , location |
啟用或停用設定 Cookie 和記錄接收到的 Cookie
on
- 啟用設定版本 2 的 Cookie 並記錄接收到的 Cookie;
v1
- 啟用設定版本 1 的 Cookie 並記錄接收到的 Cookie;
log
- 停用設定 Cookie,但啟用記錄接收到的 Cookie;
off
- 停用設定 Cookie 和記錄接收到的 Cookie。
語法 |
userid_domain |
---|---|
預設值 |
userid_domain none; |
上下文 |
http , server , location |
定義設定 Cookie 的網域。none
參數停用為 Cookie 設定網域。
語法 |
userid_expires |
---|---|
預設值 |
userid_expires off; |
上下文 |
http , server , location |
設定瀏覽器應保留 Cookie 的時間。參數 max
將導致 Cookie 在「31 Dec 2037 23:55:55 GMT
」過期。參數 off
將導致 Cookie 在瀏覽器工作階段結束時過期。
語法 |
userid_flags |
---|---|
預設值 |
userid_flags off; |
上下文 |
http , server , location |
此指令出現在 1.19.3 版本中。
如果參數不是 off
,則定義 Cookie 的一個或多個額外標誌:secure
、httponly
、samesite=strict
、samesite=lax
、samesite=none
。
語法 |
userid_mark |
---|---|
預設值 |
userid_mark off; |
上下文 |
http , server , location |
如果參數不是 off
,則啟用 Cookie 標記機制並設定用作標記的字元。此機制用於新增或變更 userid_p3p 和/或 Cookie 過期時間,同時保留客戶端識別碼。標記可以是英文字母(大小寫敏感)、數字或「=
」字元。
如果設定了標記,則會將其與 Cookie 中傳遞的客戶端識別碼的 base64 表示形式中的第一個填充符號進行比較。如果它們不匹配,則會使用指定的標記、過期時間和「P3P」標頭重新傳送 Cookie。
語法 |
userid_name |
---|---|
預設值 |
userid_name uid; |
上下文 |
http , server , location |
設定 Cookie 名稱。
語法 |
userid_p3p |
---|---|
預設值 |
userid_p3p none; |
上下文 |
http , server , location |
設定將與 Cookie 一起傳送的「P3P」標頭欄位的值。如果將指令設定為特殊值 none
,則不會在回應中傳送「P3P」標頭。
語法 |
userid_path |
---|---|
預設值 |
userid_path /; |
上下文 |
http , server , location |
定義設定 Cookie 的路徑。
語法 |
userid_service |
---|---|
預設值 |
userid_service IP address of the server; |
上下文 |
http , server , location |
如果識別碼是由多個伺服器(服務)發出的,則每個服務都應分配自己的 number
,以確保客戶端識別碼是唯一的。對於版本 1 的 Cookie,預設值為零。對於版本 2 的 Cookie,預設值是由伺服器的 IP 位址的最後四個八位元組組成的數字。
嵌入變數
ngx_http_userid_module
模組支援下列嵌入變數
$uid_got
- Cookie 名稱和接收到的客戶端識別碼。
$uid_reset
- 如果變數設定為非空字串且不是「
0
」,則會重設客戶端識別碼。特殊值「log
」還會導致將有關重設識別碼的訊息輸出到 error_log。 $uid_set
- Cookie 名稱和傳送的客戶端識別碼。