Reference
Compile
-
sudo auto/configure
This step will configure some variables and create objs/Makefile
Install PCRE, zlib if you haven’t
-
sudo make -f objs/Makefile
Add new module
add a new folder containing config and ngx_http_xxx_module.c (for example, hello/config, hello/ngx_http_hello_module.c), then configure with this argument:
then
change nginx.conf if necessary, and reload it:
Debug
- using GDB to attach nginx process
- in configuration file:
this will leave only one process for nginx
daemon off means it is no longer a daemon process. Use this setting when debug so we can use
and comment out this setting when run nginx.
Misc
ngx_cycle_modules() initialize cycle->modules from ngx_modules
ngx_preinit_modules() initialize ngx_modules from ngx_module_names
handle request
ngx_http_read_request_header(), then ngx_http_parse_request_line()
ngx_http_process_request_headers(), ngx_http_process_request_line()
upload module
ngx_http_core_main_conf_t
ngx_http.c, ngx_http_init_phase_handlers()
Questions
-
How is the settings in config file related with the code?
-
Will all the modules be linked in runtime?
No, in the function ngx_load_module(), it uses the system function dlsym() to load modules from binary. So only the modules linked during compiling will be involved.
How to work with PHP
Refer this link
- install PHP
- change nginx configuration file
add the following lines in the “server” block:
Notice: If you build nginx from source code, you need to copy fastcgi.conf and fastcgi_params into the conf/ folder manually.
- create a php file to test
its contents:
and check it out.