本文使用nginx-stable-1.12代码。 路径:
src/http/modules/ngxhttpuseridfiltermodule.c
流程图

头文件
-
// nginx配置类 -
#include <ngx_config.h> -
// nginx核心类 -
#include <ngx_core.h> -
// nginx http模块类 -
#include <ngx_http.h>
define常量
-
// off关闭功能 -
#define NGX_HTTP_USERID_OFF 0 -
// 开启log -
#define NGX_HTTP_USERID_LOG 1 -
// v1版本cookie -
#define NGX_HTTP_USERID_V1 2 -
// 开启功能 -
#define NGX_HTTP_USERID_ON 3 -
/* 31 Dec 2037 23:55:55 GMT */ // unix最大时间戳 -
#define NGX_HTTP_USERID_MAX_EXPIRES 2145916555
结构
指令
-
typedef struct { -
ngx_uint_t enable; -
ngx_int_t service; -
ngx_str_t name; -
ngx_str_t domain; -
ngx_str_t path; -
ngx_str_t p3p; -
time_t expires; -
u_char mark; -
} ngx_http_userid_conf_t;
变量
-
typedef struct { -
uint32_t uid_got[4]; -
uint32_t uid_set[4]; -
ngx_str_t cookie; -
ngx_uint_t reset; -
} ngx_http_userid_ctx_t;
函数
-
// 获取uid -
static ngx_http_userid_ctx_t *ngx_http_userid_get_uid(ngx_http_request_t *r, -
ngx_http_userid_conf_t *conf); -
-
// 变量 -
stat

本文详细分析了nginx稳定版1.12中的ngx_http_userid_module模块,涵盖流程图、指令、变量和核心函数等内容。重点讨论了如何设置和获取uid,以及在处理多域名时遇到的问题和解决方案,旨在帮助理解该模块如何实现cookie设置和用户ID跟踪。
最低0.47元/天 解锁文章
965





