英文文档对应页面:A debugging log
启用调试日志(debugging log),在安装时,nginx需要配置,以支持调试:
启用调试日志(debugging log),在安装时,nginx需要配置,以支持调试:
./configure --with-debug之后,在 “error_log” 指令中,应该设置 “debug级别”(debug level)
error_log /path/to/log debug;验证nginx是否已经配置了,支持调试(support debugging),运行 “nginx -V” 命令,会显示:
configure arguments: --with-debug预构建(pre-build)的linux的文件包,提供了二进制可执行文件 “nginx-debug” 命令(1.9.8),以外部调用的方式(out-of-the-box)支持调试日志:
service nginx stop之后,设置 “debug级别” 。windows下的nginx二进制文件版本,总是支持 “调试日志”,因此,只需要设置 “debug级别” 即可
service nginx-debug start
注意:重新定义 “error_log” 指令,但未指定 “debug级别”,将禁用 “调试日志”。例如下面的例子,在 “server”块 中重新定义了log,未指定 “debug级别”:
error_log /path/to/log debug;
http {
server {
error_log /path/to/log; // 未指定 debug level
}
}
为了避免这种情况,重定义时,必须指定 “debug级别”
error_log /path/to/log debug;
http {
server {
error_log /path/to/log debug; // 必须指定 debug level
}
}
为指定的客户端,开启调试日志
为指定的客户端,开启调试日志也是可以的,使用如下配置:error_log /path/to/log;
events {
debug_connection 192.168.1.1;
debug_connection 192.168.10.0/24;
}
记录日志到一个循环的内存缓冲区
调试日志也可以写入到一个循环的内存缓存区(a cyclic memory buffer)error_log memory:32m debug;在 “debug级别” 记录日志到内存缓冲区,即使在高负载时,也不会对性能有大的影响。因此,可以使用一个 “gdb脚本”(gdb script)来从内存中获取日志??,例如:
set $log = ngx_cycle->log
while $log->writer != ngx_log_memory_writer
set $log = $log->next
end
set $buf = (ngx_log_memory_buf_t *) $log->wdata
dump binary memory debug_log.txt $buf->start $buf->end