#directives
Posts
-
Digging into nginx's Source 4: Startup and Reading the Config — From main() to ngx_init_cycle
When you start nginx, main() reads the command line, and ngx_init_cycle() reads nginx.conf and builds one complete set of configuration called a cycle — only then does the master process start running. We follow how one parser function handles three cases (a file, a block, and the -g command-line string), how ngx_conf_read_token() splits text into words one character at a time, where the error messages come from, and how reload calls the same ngx_init_cycle() again and inherits listening sockets and shared memory from the old cycle — using the nginx 1.31.9 source and gdb and strace examples.
-
Digging into nginx's Source 5: Modules and Directives — How One Line of nginx.conf Becomes a Module's Config Struct
An nginx module is a single ngx_module_t struct, and a directive is one row in the ngx_command_t table that struct points to. We follow the module array configure generates, dynamic modules read with load_module, ngx_conf_handler() finding a function by directive name, ngx_http_block() creating per-module config structs for every http, server and location, and the merge that finishes once, at config time. We build a dynamic module with four directives to watch the callback order, the merged values and the error messages.
-
Digging into Apache httpd's Source 7: The Config File and Directives — How One Line of httpd.conf Becomes a C Struct
How does one line you write in httpd.conf end up calling a module's C function and filling in a struct? We follow server/config.c — reading the file into a tree and then walking it, the hash that finds a directive by name, argument styles like TAKE1, FLAG and ITERATE, the bit test behind "not allowed here" and AllowOverride, and when the values in Directory, Location and VirtualHost sections get merged — all checked with a directive we wrote ourselves.