可是章老师我还是有个地方不是很明白,在ngx_http_rewrite_handler函数内部
有几句代码是
ngx_http_core_srv_conf_t *cscf;
cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
if (r->phase_handler == index && r->loc_conf == cscf->ctx->loc_conf) {
/* skipping location rewrite phase for server null location */
return NGX_DECLINED;
}
其中cscf->ctx->loc_conf与r->loc_conf在什么时候是相等的,在什么情况下又是不相等的呢??
cscf->ctx->loc_conf与r->loc_conf的关系又是什么呢?
nginx_http_core_module 中定义的struct ngx_http_core_loc_conf_s结构体中的loc_conf与上述两者又是什么关系呢?
在 2014年11月20日星期四UTC+8上午4时35分40秒,agentzh写道:
Hello!
2014-11-18 23:35 GMT-08:00 冰河:
> 在ngx_http_core_post_rewrite_phase函数中
> 当r->uri_changed不为0时,该request需要重新匹配location,于是就会再次执行ngx_http_core_find_config_phase函数为
> r->loc_conf 赋值。
>
nginx 的 rewrite 指令发起的跳转是一种特殊的内部跳转。显然,原作者在这里希望它和标准的内部跳转(即
ngx_http_internal_redirect 发起的)一样跳回到 server rewrite 阶段,所以如此初始化
r->loc_conf. 但不幸的是,这种 rewrite 发起的特殊跳转并不会跳回到 server rewrite 阶段。所以可以视作
copy&paste 的残留吧。
Regards,
-agentzh