ngx_http_join_exact_locations
1 定义ngx_http_join_exact_locations 函数 定义在 ./nginx-1.24.0/src/http/ngx_http.cstaticngx_int_tngx_http_join_exact_locations(ngx_conf_t*cf,ngx_queue_t*locations){ngx_queue_t*q,*x;ngx_http_location_queue_t*lq,*lx;qngx_queue_head(locations);while(q!ngx_queue_last(locations)){xngx_queue_next(q);lq(ngx_http_location_queue_t*)q;lx(ngx_http_location_queue_t*)x;if(lq-name-lenlx-name-lenngx_filename_cmp(lq-name-data,lx-name-data,lx-name-len)0){if((lq-exactlx-exact)||(lq-inclusivelx-inclusive)){ngx_log_error(NGX_LOG_EMERG,cf-log,0,duplicate location \%V\ in %s:%ui,lx-name,lx-file_name,lx-line);returnNGX_ERROR;}lq-inclusivelx-inclusive;ngx_queue_remove(x);continue;}qngx_queue_next(q);}returnNGX_OK;}ngx_http_join_exact_locations 函数的作用是 将 URI 相同的精确匹配location /uri和前缀匹配location /uri合并到同一个链表节点中。2 详解1 函数签名staticngx_int_tngx_http_join_exact_locations(ngx_conf_t*cf,ngx_queue_t*locations)返回值 返回 NGX_OK通常为 0表示成功。 返回 NGX_ERROR通常为 -1表示失败。参数 ngx_conf_t *cf 指向配置解析上下文 ngx_queue_t *locations location 配置链表的头节点哨兵节点2 逻辑流程1 局部变量 2 遍历查找 URI 相同的相邻节点 3 返回成功1 局部变量{ngx_queue_t*q,*x;ngx_http_location_queue_t*lq,*lx;2 遍历查找 URI 相同的相邻节点qngx_queue_head(locations);while(q!ngx_queue_last(locations)){xngx_queue_next(q);lq(ngx_http_location_queue_t*)q;lx(ngx_http_location_queue_t*)x;if(lq-name-lenlx-name-lenngx_filename_cmp(lq-name-data,lx-name-data,lx-name-len)0){if((lq-exactlx-exact)||(lq-inclusivelx-inclusive)){ngx_log_error(NGX_LOG_EMERG,cf-log,0,duplicate location \%V\ in %s:%ui,lx-name,lx-file_name,lx-line);returnNGX_ERROR;}lq-inclusivelx-inclusive;ngx_queue_remove(x);continue;}qngx_queue_next(q);}#1 获取队列 locations 的头节点指针赋值给 q#2 循环条件判断当前节点 q 是否是队列的最后一个节点#3 获取当前节点 q 的下一个节点指针赋值给 x#4 将通用的 ngx_queue_t 节点指针强制转换为具体的 ngx_http_location_queue_t 类型指针#5 判断相邻两个 location 的路径是否完全相同。#6 检查两个 location 的匹配类型是否冲突 完全重复的类型定义这是配置错误 输出错误日志 返回错误码#7 将后一个节点 lx 的 inclusive 标志赋值给前一个节点 lq#8 从队列中删除节点 x#9 当相邻两个节点路径不同时 将 q 移动到下一个节点3 返回成功returnNGX_OK;}
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2467107.html
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!