nginx_conf_layout

Overview

1
2
3
4
5
6
http {
server {
location /sdf {
}
}
}

each block has a context, child block may share part of context with its parent, like server block shares main_conf with its parent http block, location block shares main_conf and srv_conf with its parent server block, except the sharing part, each context preserve a slot for all HTTP modules, each HTTP module has it own create_main/create_srv/create_loc if it wants to save parameters from cmd at different scopes(MAIN_CONF/SER_CONF/LOC_CONF), let’s say an example to explain it.

  • if a HTTP module has a command can be used only at MAIN_CONF scope, it only needs to provide create_main function which only called at http block {}
  • if a HTTP module has a command can be used only at SRV_CONF scope, it has to provide create_srv function called both by http block {} and server block {}, but http block {} created part is not used actually because command is not allowed to use at http block, no merge needed.
  • if a module has a command can be used at MAIN_CONF/SRV_CONF scope, it has to provide create_srv function called both by http block {} and server block {}, then merge the value set at http block to server block {} at last.

conf layout

conf ctx layout

http

http ctx layout

For each HTTP module that provides create_srv, it’s called once at http level, then for each server {}, it’s called once at server level as well, that means we merge http {} same srv_conf with different srv_conf at server {}.

stream

stream ctx layout