代码编译

wget http://nginx.org/download/nginx-1.13.8.tar.gz
wget https://www.openssl.org/source/openssl-1.1.1h.tar.gz
tar xzvf nginx-1.13.8.tar.gz 
tar xzvf openssl-1.1.1h.tar.gz
pushd nginx-1.13.8

# 启用debug,关闭编译器优化
./configure --with-debug --with-cc-opt='-O0 -g' --with-http_stub_status_module --with-http_ssl_module --with-openssl=../openssl-1.1.1h  --add-module=`pwd`/nginx-hello-world-module 
vi conf/test.conf
make -j 24 && ./objs/nginx -p `pwd` -c conf/test.conf

测试用配置文件,关闭master-worker模式,仅一个进程,方便调试1

# conf/test.conf
daemon off;
master_process off;
events {
	debug_connection 127.0.0.1;
}

http {
	server {
		listen 8085;
		location /status {
			stub_status on;
		}
		location /hello {
			hello_world;
		}
	}
}

vs code 调试配置2,需要先安装gdb

{
	"version": "0.2.0",
	"configurations": [
		{
			"name": "(gdb) 启动",
			"type": "cppdbg",
			"request": "launch",
			"program": "${workspaceFolder}/objs/nginx",
			"args": [
				"-p",
				"${workspaceFolder}",
				"-c",
				"conf/test.conf"
			],
			"stopAtEntry": false,
			"cwd": "${workspaceFolder}",
			"environment": [],
			"externalConsole": false,
			"MIMode": "gdb",
			"setupCommands": [
				{
					"description": "为 gdb 启用整齐打印",
					"text": "-enable-pretty-printing",
					"ignoreFailures": true
				},
				{
					"description": "将反汇编风格设置为 Intel",
					"text": "-gdb-set disassembly-flavor intel",
					"ignoreFailures": true
				}
			]
		}
	]
}