← 블로그 목록
작성일: 2026-05-29 에러 로그500 에러502 에러

Nginx/Apache 에러 로그 분석으로 서버 문제 진단하기

액세스 로그는 요청 기록이지만, 에러 로그는 서버 내부에서 발생한 문제를 기록합니다. 500 에러의 원인, PHP 오류, 파일 권한 문제 등 서비스 장애의 근본 원인은 에러 로그에서 찾을 수 있습니다.


에러 로그 파일 위치


Nginx 에러 로그 구조

2024/10/10 14:05:22 [error] 12345#12345: *678 open() "/var/www/html/favicon.ico" failed (2: No such file or directory), client: 192.0.2.100, server: example.com, request: "GET /favicon.ico HTTP/1.1", host: "example.com"


주요 에러 유형

1. 파일 없음 (404)

open() "/var/www/html/missing.jpg" failed (2: No such file or directory)

원인: 링크된 파일이 실제로 없음 해결: 파일 업로드 또는 링크 수정

2. 권한 거부 (403)

open() "/var/www/html/admin/config.php" failed (13: Permission denied)

원인: Nginx 프로세스(www-data)가 파일 읽기 권한 없음 해결:

sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html

3. FastCGI 연결 실패 (502)

connect() to unix:/run/php/php8.2-fpm.sock failed (2: No such file or directory)

원인: PHP-FPM 서비스가 중단됨 해결:

sudo systemctl status php8.2-fpm
sudo systemctl start php8.2-fpm

4. 업스트림 타임아웃 (504)

upstream timed out (110: Connection timed out) while reading response header from upstream

원인: 백엔드 서버(PHP/Python 등)가 60초 안에 응답 못 함 해결: 타임아웃 늘리기

location ~ \.php$ {
    fastcgi_read_timeout 300;
}

5. 메모리 부족 (500)

recv() failed (104: Connection reset by peer) while reading response header from upstream

원인: PHP 메모리 제한 초과 해결: /etc/php/8.2/fpm/php.ini에서

memory_limit = 256M

Apache 에러 로그 구조

[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


에러 로그 레벨

Nginx/Apache 모두 동일한 레벨 체계:

웹 서버로그 경로
Nginx/var/log/nginx/error.log
Apache (Ubuntu)/var/log/apache2/error.log
Apache (CentOS)/var/log/httpd/error_log
필드의미
날짜/시각2024/10/10 14:05:22
로그 레벨[error] (debug/info/notice/warn/error/crit/alert/emerg)
프로세스 ID12345#12345 (마스터#워커)
연결 ID*678
메시지open() failed...
클라이언트 IP192.0.2.100
서버명example.com
요청GET /favicon.ico HTTP/1.1
필드의미
날짜/시각Fri Oct 10 14:05:22.123456 2024
모듈:레벨[core:error]
프로세스 ID[pid 12345]
클라이언트[client 192.0.2.100:54321]
메시지File does not exist...
레벨심각도의미
emerg최고시스템 사용 불가
alert매우 높음즉시 조치 필요
crit높음치명적 오류
error중간일반 오류 (기본 로깅)
warn낮음경고
notice매우 낮음주목할 이벤트
info정보정보성 메시지
debug디버그개발 전용
운영 환경에서는 error 레벨만 로깅하는 것이 일반적입니다.


에러 로그 분석 명령어

가장 많이 발생한 에러

awk '{for(i=1;i<=NF;i++){if($i~/\[error\]/){print;break}}}' /var/log/nginx/error.log \
  | sort | uniq -c | sort -rn | head -10

특정 시간대 에러

grep '2024/10/10 14:' /var/log/nginx/error.log

PHP Fatal Error 찾기

grep -i 'fatal error' /var/log/nginx/error.log

502/504 에러 원인

grep -E '(upstream timed out|connect\(\) failed)' /var/log/nginx/error.log

로그 레벨 조정

Nginx

/etc/nginx/nginx.conf:

error_log /var/log/nginx/error.log warn;  # error → warn으로 변경

Apache

/etc/apache2/apache2.conf:

LogLevel warn  # error → warn

재시작 필요:

sudo systemctl restart nginx
sudo systemctl restart apache2

에러 로그 로테이션

/etc/logrotate.d/nginx:

/var/log/nginx/*.log {
    daily
    missingok
    rotate 14
    compress
    delaycompress
    notifempty
    create 0640 www-data adm
    sharedscripts
    postrotate
        [ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
    endscript
}

정리

에러 로그는 500/502/504 에러의 실제 원인을 알려줍니다. 파일 권한, FastCGI 연결 실패, 타임아웃, 메모리 부족 등 액세스 로그만으로는 알 수 없는 서버 내부 문제를 진단할 수 있습니다.