Home  >  Article  >  Backend Development  >  nginx source code (3) debugging

nginx source code (3) debugging

WBOY
WBOYOriginal
2016-08-08 09:28:021261browse

Continued from the previous article

nginx runs as a background process when running, one master and three process processes. In order to facilitate debugging, this configuration needs to be changed.

Change the source code directly here. In order to make it easier to make again, modify the Makefile first
Changed from the original

<code><span>clean:</span>
    rm -rf Makefile objs</code>

to:

<code><span>clean</span>:
    rm -rf nginx objs<span>/ngx_modules.o objs/src/core*.o objs/src/event/</span>*.o objs<span>/src/event/modules/</span>*.o objs<span>/src/http/</span>*.o objs<span>/src/http/modules/</span>*.o objs<span>/src/http/modules/proxy/</span>*.o objs<span>/src/os/unix/</span>*.o</code>

so that all Makefile files will not be deleted after make clean.

Comment out the code related to daemon and multi-process in core/nginx.c:

<code><span>/*
    if (!ngx_inherited && ccf->daemon) {
        if (ngx_daemon(cycle->log) == NGX_ERROR) {
            return 1;
        }

        ngx_daemonized = 1;
    }
    */</span></code>

and

<code><span>printf</span>(<span>"[main] to start ngx_single_process_cycle\n"</span>);

    <span>///if (ngx_process == NGX_PROCESS_MASTER) {</span><span>///    ngx_master_process_cycle(cycle, &ctx);</span><span>///} else {</span>
        ngx_single_process_cycle(cycle, &ctx);
    <span>///}</span></code>

I added a printf above, because nginx runs directly in the console to verify the printing and for subsequent startup Conveniently, change the port number in conf/nginx.conf to 8080, re-run make, and you can see the output printed on the console. When the browser accesses http://localhost:8080, success is also returned, and other log information is still output in files in the logs directory.

The above introduces the debugging of nginx source code (3), including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn