Heim  >  Artikel  >  Backend-Entwicklung  >  nginx 源码(3)调试

nginx 源码(3)调试

WBOY
WBOYOriginal
2016-08-08 09:28:021263Durchsuche

接上一篇

nginx运行的时候以后台进程运行,一个master和3个process进程,为了方便调试,需要改一下这个配置。

这里直接改源码,为了重新make方便,先修改Makefile
从原来的

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

修改为:

<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>

这样make clean之后不会全部删除Makefile文件。

把core/nginx.c中与daemon和多进程相关的代码注释掉:

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

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

<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>

我在上面加了一个printf,因为nginx直接在console中运行,验证打印,同时为了后续启动方便,把conf/nginx.conf中的端口号改为8080,重新make运行,可以看到控制台打印了输出。浏览器访问http://localhost:8080, 同样返回success,其他的日志信息还是输出在logs目录下的文件中。

以上就介绍了nginx 源码(3)调试,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:软件工程师应该多写文章Nächster Artikel:CentOS yum 安装 nginx