1 | 源码编译安装Nginx
cd /home/codes/
wget http://nginx.org/download/nginx-1.16.1.tar.gz
tar zxvf nginx-1.16.1.tar.gz && cd nginx-1.16.1
./configure --prefix=/application/nginx-1.16.1/ --with-debug --with-cc-opt='-O0 -g'
make && make install
其中 --with-cc-opt='-O0 -g'
是不对编译进行优化和打开调试开关,-O0 -O1 -O2 -O3 -Os
的作用请自行搜索
2 | 使用gdb调试
/application/nginx-1.16.1/sbin/nginx
#查看worker的pid
ps -ef | grep nginx
gdb -p 1706
#b src/http/ngx_http_core_module.c:1740 #需要根据nginx的版本查询ngx_http_send_header的行数打断点,其实也可以按照以下方式进行打断点
b ngx_http_send_header
p *r #r是ngx_http_request_s
ngx_http_request_s结构体
struct ngx_http_request_s {
uint32_t signature; /* "HTTP" */
ngx_connection_t *connection;
void **ctx;
void **main_conf;
void **srv_conf;
void **loc_conf;
ngx_http_event_handler_pt read_event_handler;
ngx_http_event_handler_pt write_event_handler;
#if (NGX_HTTP_CACHE)
ngx_http_cache_t *cache;
#endif
ngx_http_upstream_t *upstream;
ngx_array_t *upstream_states;
/* of ngx_http_upstream_state_t */
ngx_pool_t *pool;
ngx_buf_t *header_in;
ngx_http_headers_in_t headers_in;
ngx_http_headers_out_t headers_out;
ngx_http_request_body_t *request_body;
time_t lingering_time;
time_t start_sec;
ngx_msec_t start_msec;
ngx_uint_t method;
ngx_uint_t http_version;
ngx_str_t request_line;
ngx_str_t uri;
ngx_str_t