디버깅 로그
nginx는 디버깅 로그를 활성화하려면, 빌드 중에 디버깅을 지원하도록 구성해야 합니다.
./configure --with-debug ...
그런 다음, debug 레벨을 error_log 명령으로 설정해야 합니다.
error_log /path/to/log debug;
nginx가 디버깅을 지원하도록 구성되었는지 확인하려면 nginx -v 명령을 실행하세요.
configure arguments: --with-debug ...
사전 구축된 Linux 패키지는 nginx-debug 바이너리(1.9.8)로 디버깅 로그를 기본 지원합니다.
service nginx stop
service nginx-debug start
위 명령을 사용하여 실행하고 debug 레벨을 설정합니다. Windows용 nginx 바이너리 버전은 언제나 디버깅 로그를 지원하도록 구축되므로 debug 레벨을 설정하는 것만으로 충분합니다.
debug 레벨을 지정하지 않고 로그를 다시 정의할 경우 디버깅 로그가 비활성화됩니다. 아래의 예시에서 server 레벨에서 로그를 다시 정의하면 이 서버의 디버깅 로그가 비활성화됩니다.
error_log /path/to/log debug;
http {
server {
error_log /path/to/log;
...
이런 현상을 피하려면 로그를 재정의하는 행을 주석 처리하거나 debug 레벨 사양도 추가해야 합니다.
error_log /path/to/log debug;
http {
server {
error_log /path/to/log debug;
...
선택한 클라이언트에 대한 디버깅 로그
또한, 선택한 클라이언트 주소에만 디버깅 로그를 활성화할 수 있습니다.
error_log /path/to/log;
events {
debug_connection 192.168.1.1;
debug_connection 192.168.10.0/24;
}
순환적 메모리 버퍼에 로깅
디버깅 로그는 순환적 메모리 버퍼에 작성할 수 있습니다.
error_log memory:32m debug;
debug 레벨에서 메모리 버퍼에 로깅하면 부하가 높을 때도 성능에 큰 영향을 미치지 않습니다. 이 경우, 다음과 같이 gdb 스크립트를 사용하여 로그를 추출할 수 있습니다.
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