搭建nginx 1.22.1源代码编译调试环境

前言:搭建nginx 1.22.1源代码编译调试环境笔记

参考文章:https://www.mazhen.tech/p/在macos上使用vscode调试nginx/

环境搭建

nginx

https://nginx.org/download/nginx-1.22.1.tar.gz

pcre

https://sourceforge.net/projects/pcre/files/pcre/8.45/pcre-8.45.tar.gz/download

zlib

https://zlib.net/zlib-1.2.13.tar.gz

openssl-1.1.1s

https://www.openssl.org/source/openssl-1.1.1s.tar.gz

编译

nginx.conf

为了调试方便,可以修改默认配置 conf/nginx.conf,关闭 daemon,并以单进程模式运行:

daemon off;
master_process off;

configure

使用 configure 命令进行相关编译参数配置:

--with-debug 启用 debugging log
--with-cc-opt='-O0 -g' ,使用 -g 包含 debug 符号信息,-O0标志禁用编译器优化
--prefix 指定安装目录
--with-... 指定依赖的源码位置

./configure --with-debug --with-cc-opt='-O0 -g' \
--prefix=./dist \
--with-http_ssl_module \
--with-pcre=../pcre-8.45 \
--with-zlib=../zlib-1.2.13 \
--with-openssl=../openssl-1.1.1s
make && make install

vscode调试

复制dist/下的conf,html,logs目录到dist/sbin目录下

vscode的调试文件launch.json

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "debuug php source",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/dist/sbin/nginx",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}/dist/sbin/",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb"
        }
        

    ]
}

调试情况如下所示

posted @ 2023-02-01 19:54  zpchcbd  阅读(444)  评论(0编辑  收藏  举报