http配置项的使用场景
http{
test_str main;
server{
listen 80;
test_str server80;
location /url1{
mytest;
test_str loc1;
}
location /url2{
mytest;
test_str loc2;
}
}
server {
listen 8080;
test_str server8080;
location /url3{
mytest;
test_str loc3;
}
}
}
怎样使用http配置
- 创建数据结构存储配置项对应的参数
- 设定配置项在nginx.conf中出现时的限制条件与回调方法
- 实现2中的回调方法,或者使用nginx框架预设的14个回调方法
- 合并不同级别的配置块中出现的同名配置
分配用于保存配置参数的数据结构
创建结构体,包含感兴趣的参数,以14种预设配置项的解析为例
使用回调函数将自定义的结构体传递给nginx
设定配置项的解析方式
ngx_command_t
使用14种预设方法解析配置项
ngx_conf_set_flag_slot
ngx_conf_set_str_slot
ngx_conf_set_str_array_slot
ngx_conf_set_keyval_slot
其他类似
自定义配置项处理方法
- 首先定义配置项处理方法
static char* ngx_conf_set_myconfig(ngx_conf_t *cf,ngx_command_t *cmd,void *conf) - 接下来定义ngx_command_t 结构体
合并配置项
http配置模型
通过ngx_http_conf_ctx_t结构保存了所有http模块的配置数据结构的入口。
解析http配置的流程
http匹配模型的内存布局
如何合并配置项
error日志的用法
请求的上下文
上下文与全异步Web服务器的关系
需要局部来维护