: This article mainly introduces nginx source code (3) Debugging. For more information about PHP tutorials, see. Next
After nginx is run, a master and three process processes run. to facilitate debugging, you need to modify this configuration.
Change the source code directly here. to make it more convenient, modify the Makefile first.
From the original
clean: rm -rf Makefile objs
To:
clean: rm -rf nginx objs/ngx_modules.o objs/src/core*.o objs/src/event/*.o objs/src/event/modules/*.o objs/src/http/*.o objs/src/http/modules/*.o objs/src/http/modules/proxy/*.o objs/src/os/unix/*.o
In this way, the Makefile files will not be all deleted after make clean.
Comment out the daemon and multi-process-related code in core/nginx. c:
/* if (!ngx_inherited && ccf->daemon) { if (ngx_daemon(cycle->log) == NGX_ERROR) { return 1; } ngx_daemonized = 1; } */
And
printf("[main] to start ngx_single_process_cycle\n"); ///if (ngx_process == NGX_PROCESS_MASTER) {/// ngx_master_process_cycle(cycle, &ctx);///} else { ngx_single_process_cycle(cycle, &ctx); ///}
I added a printf on it because nginx runs directly on the console to verify the printing. at the same time, for convenience of subsequent startup, the conf/nginx. change the port number in conf to 8080 and run make again. The output is printed on the console. When the browser accesses http: // localhost: 8080, success is also returned. other log information is output to the file in the logs directory.