nginx.org的A debugging log页面翻译

本文介绍如何在Nginx中配置调试日志,包括启用调试日志的方法、设置不同级别的调试信息、针对特定客户端开启调试日志及将日志记录到内存缓冲区等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

英文文档对应页面:A debugging log

启用调试日志(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
service nginx-debug start
之后,设置 “debug级别” 。windows下的nginx二进制文件版本,总是支持 “调试日志”,因此,只需要设置 “debug级别” 即可

注意:重新定义 “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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值