라이브러리
[NGINX] error_log - Nginx의 에러 로그 파일 경로를 설정합니다.
NGINX 에서 error_log는 NGINX 서버의 오류 로그를 기록하는 기능입니다. NGINX 서버가 오류를 발생할 때, error_log를 통해 오류의 내용을 기록할 수 있습니다. 이 기능은 NGINX 서버의 운영 및 관리에 매우 중요합니다.
error_log의 기본 구성
NGINX 에서 error_log는 다음과 같은 기본 구성이 있습니다.
#hostingforum.kr
bash
error_log /var/log/nginx/error.log;
위의 코드는 NGINX 서버의 오류 로그를 `/var/log/nginx/error.log` 파일에 기록합니다.
error_log의 옵션
error_log에는 다음과 같은 옵션들이 있습니다.
- `level`: 오류 레벨을 지정합니다. 예를 들어, `error`, `warn`, `info`, `debug` 등이 있습니다.
- `format`: 오류 로그의 형식을 지정합니다. 예를 들어, `combined` 또는 `json` 등이 있습니다.
- `buffer_size`: 오류 로그를 버퍼링하는 크기를 지정합니다.
- `gzip`: 오류 로그를 압축하는지 여부를 지정합니다.
예제
다음은 NGINX 에서 error_log를 사용하는 예제입니다.
#hostingforum.kr
bash
http {
...
error_log /var/log/nginx/error.log notice;
error_log /var/log/nginx/error.log debug;
log_format combined '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log combined;
error_log /var/log/nginx/error.log combined;
}
위의 코드는 NGINX 서버의 오류 로그를 `/var/log/nginx/error.log` 파일에 기록하고, 오류 로그의 형식을 `combined`로 지정합니다. 또한, 오류 로그의 레벨을 `notice`와 `debug`로 지정합니다.
실습
실습을 위해, NGINX 서버를 설치하고, 다음과 같은 NGINX 구성 파일을 생성합니다.
#hostingforum.kr
bash
http {
server {
listen 80;
server_name example.com;
location / {
root /var/www/html;
index index.html;
}
error_log /var/log/nginx/error.log notice;
error_log /var/log/nginx/error.log debug;
log_format combined '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log combined;
error_log /var/log/nginx/error.log combined;
}
}
위의 코드는 NGINX 서버의 오류 로그를 `/var/log/nginx/error.log` 파일에 기록하고, 오류 로그의 형식을 `combined`로 지정합니다. 또한, 오류 로그의 레벨을 `notice`와 `debug`로 지정합니다.
NGINX 서버를 재시작하고, 다음 명령어를 실행하여 오류 로그를 확인합니다.
#hostingforum.kr
bash
tail -f /var/log/nginx/error.log
위의 명령어는 오류 로그를 실시간으로 확인할 수 있습니다.
댓글목록
등록된 댓글이 없습니다.