디버깅 로그 (Debugging log)
nginx에서 디버그 기능을 쓰려면 빌드할 때 디버깅 지원을 활성화하고 로그 레벨을 debug로 설정해야 해요. 어떤 상황에서 문제의 원인을 찾아야 할 때 유용하답니다.
출처: 문서
본문
디버깅 로그를 활성화하려면 빌드할 때 nginx가 디버깅을 지원하도록 설정해야 해요:
./configure --with-debug ...
그다음 error_log 지시어로 debug 레벨을 설정해요:
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;
}
순환 메모리 버퍼로 로깅하기
디버깅 로그는 순환 메모리 버퍼(cyclic memory buffer)에 기록할 수 있어요:
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
또는 다음과 같은 lldb 스크립트로 추출할 수 있어요:
expr ngx_log_t *$log = ngx_cycle->log
expr while ($log->writer != ngx_log_memory_writer) { $log = $log->next; }
expr ngx_log_memory_buf_t *$buf = (ngx_log_memory_buf_t *) $log->wdata
memory read --force --outfile debug_log.txt --binary $buf->start $buf->end
더 알아보기 (Learn more)
- nginx 제어하기 (Controlling nginx) — 로그 파일 다시 열기(USR1)
- 소스에서 nginx 빌드하기 —
--with-debug빌드 옵션 - 이벤트 (Events) —
debug_connection디렉티브 관련 컨텍스트