← 블로그 목록
작성일: 2026-05-24 Apache로그 분석Combined Log Format

Apache 액세스 로그 분석 완벽 가이드

Apache HTTP Server는 Nginx와 함께 가장 널리 사용되는 웹 서버입니다. Apache의 Combined Log Format은 업계 표준이 되어 많은 웹 서버가 이 포맷을 따르고 있습니다. 이 글에서는 Apache 로그의 구조와 분석 방법을 자세히 설명합니다.


Apache 로그 파일 위치


Combined Log Format 구조

Apache의 기본 로그 포맷은 다음과 같이 정의됩니다.

``apache LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined `

실제 로그 라인:

` 192.0.2.100 - frank [10/Oct/2024:13:55:36 -0700] "GET /admin HTTP/1.1" 403 287 "http://example.com/" "Mozilla/5.0" `

배포판로그 경로
------------------
Ubuntu/Debian/var/log/apache2/access.log
CentOS/RHEL/var/log/httpd/access_log
macOS (Homebrew)/usr/local/var/log/httpd/access_log
필드의미예시 값
---------------------
%h클라이언트 IP192.0.2.100
%l식별자 (대부분 -)-
%u인증된 사용자frank (없으면 -)
%t요청 시각[10/Oct/2024:13:55:36 -0700]
%r요청 라인GET /admin HTTP/1.1
%>s최종 응답 코드403
%b응답 바이트 수287 (없으면 -)
%{Referer}i참조 URLhttp://example.com/
%{User-Agent}i클라이언트 식별자Mozilla/5.0

Nginx와 Apache 로그 차이점

날짜 포맷

  • Nginx: 10/May/2024:03:21:05 +0000 (초 단위, UTC 명시)
  • Apache: 10/Oct/2024:13:55:36 -0700 (초 단위, 타임존 offset)

응답 크기 표기

  • Nginx: 항상 숫자 (0 포함)
  • Apache: 바이트가 없으면 -로 표기

로그 디렉티브

Nginx (nginx.conf): `nginx log_format main '$remote_addr - $remote_user [$time_local] ...'; access_log /var/log/nginx/access.log main; `

Apache (httpd.conf 또는 apache2.conf): `apache LogFormat "%h %l %u %t \"%r\" %>s %b" common CustomLog /var/log/apache2/access.log common `


응답시간 추가하기

기본 포맷에는 응답시간이 없습니다. 성능 분석을 위해 %D 또는 %T를 추가하세요.

`apache LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %T/%D" combined_time CustomLog /var/log/apache2/access.log combined_time `

  • %T: 초 단위 (정수, 예: 1)
  • %D: 마이크로초 단위 (예: 1234567 = 1.234567초)
재시작 후 로그 예시: ` 192.0.2.100 - - [10/Oct/2024:14:00:00 -0700] "GET /api/data HTTP/1.1" 200 4821 "-" "curl/7.68.0" 0/312442 `

마지막 0/312442는 0초 / 312,442 마이크로초 = 약 0.312초


가상 호스트별 로그 분리

Apache는 가상 호스트마다 별도 로그 파일을 만들 수 있습니다.

`apache ServerName example.com CustomLog /var/log/apache2/example.com-access.log combined ErrorLog /var/log/apache2/example.com-error.log

ServerName blog.example.com CustomLog /var/log/apache2/blog-access.log combined ErrorLog /var/log/apache2/blog-error.log `


로그 분석 명령어

가장 많이 접근한 경로

`bash awk '{print $7}' /var/log/apache2/access.log | sort | uniq -c | sort -rn | head -20 `

403/401 에러를 가장 많이 받은 IP

`bash awk '$9 ~ /40[13]/ {print $1}' /var/log/apache2/access.log | sort | uniq -c | sort -rn | head -20 `

응답시간 기준 가장 느린 요청 (마이크로초)

`bash awk '{print $NF, $7}' /var/log/apache2/access.log | sed 's/\/.*//' | sort -rn | head -20 `

시간대별 요청 분포

`bash awk '{print $4}' /var/log/apache2/access.log | cut -d: -f2 | sort | uniq -c `


에러 로그 분석

액세스 로그는 요청을, 에러 로그는 서버 내부 문제를 기록합니다.

`bash tail -f /var/log/apache2/error.log `

에러 로그 예시:

` [Fri Oct 10 14:05:22.123456 2024] [core:error] [pid 12345] [client 192.0.2.100:54321] File does not exist: /var/www/html/favicon.ico [Fri Oct 10 14:06:00.987654 2024] [php7:error] [pid 12346] [client 192.0.2.101:54322] script '/var/www/html/index.php' not found or unable to stat `


Apache 로그 로테이션

Ubuntu/Debian은 logrotate가 자동으로 로그를 관리합니다.

/etc/logrotate.d/apache2:

` /var/log/apache2/*.log { daily missingok rotate 14 compress delaycompress notifempty create 640 root adm sharedscripts postrotate if /etc/init.d/apache2 status > /dev/null ; then \ /etc/init.d/apache2 reload > /dev/null; \ fi; endscript } `

  • daily: 매일 로테이션
  • rotate 14: 14일치 보관
  • compress: 오래된 로그 gzip 압축
  • postrotate: 로테이션 후 Apache 리로드

CloudFlare 뒤에 있을 때 실제 IP 기록

CDN/프록시를 사용하면 모든 요청 IP가 프록시 IP로 기록됩니다. X-Forwarded-For 헤더를 로그에 포함하세요.

`apache LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" cloudflare CustomLog /var/log/apache2/access.log cloudflare ``


정리

Apache 로그는 Nginx와 유사하지만 날짜 포맷, 응답 크기 표기, 설정 문법이 다릅니다. 가상 호스트별 로그 분리, 응답시간 추가, 실제 IP 기록 설정을 통해 더 정확한 분석이 가능합니다.