question about ngx_http_named_location

Maxim Dounin mdounin at
Fri Aug 31 18:52:26 UTC 2012


On Wed, Aug 29, 2012 at 02:43:04PM +0300, Anatoli Marinov wrote:

> Hello Mates,
> I am wondering why in ngx_http_named_location is used a segment of
> code that resets all modules contexts. I mean the line
> ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);.
> My opinion is that the module context should not be touched outside
> of the certain module. Is there a special reason for this patch? Is
> there a case which requires it?

There was more than one case where not clearing of module 
contexts in ngx_http_named_location() was causing problems, see 
here for more details:

As this behaviour wasn't something designed (rather a bug, even if 
not affecting official modules), nor something consistent with 
other similar code (i.e. clearing module contexts on internal 
redirects), hence it was decided that it's better to clear context 
than to don't.

As for clearing module contexts on internal redirects (in contrast 
to named locations - where behaviour was changed recently, and the 
change is explained above), it allows to simplify module 
development as modules don't need to keep track of request 
processing history.  And actually it semantically does what internal 
redirect is expected to do: start another request with another 

There is at least one way to preserve data between both internal 
redirects and named location changes (as well as subrequests, 
actually), via variables.  (It's somewhat a hack, but it works and 
it's expected to work.  You may try searching mailing list 
archives for more details, I believe I explained this at least 

Maxim Dounin

More information about the nginx-devel mailing list