Nginx 로깅 및 지표
Nginx 접근 로그와 오류 로그를 설정하고 모니터링 및 분석을 위해 지표를 추출하는 방법을 살펴보세요.
Nginx 로깅 및 지표은(는) CoddyKit의 무료 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Why Nginx Logs Matter
Nginx logs are vital for understanding your server's activity and health. They record every request and any issues that occur.
Think of them as your server's diary. By reviewing these logs, you can monitor performance, troubleshoot errors, identify security threats, and gather valuable usage metrics.
Understanding Access Logs
Access logs record every request Nginx processes. Each line details a single client request, providing insights into who accessed what, and when.
- Client IP: Who made the request.
- Request method & URL: What was requested.
- Status code: Was it successful (200), an error (404, 500), etc.?
- Response size: How much data was sent back.
- User-Agent: The client's browser/device.
Default Access Log Format
By default, Nginx uses the 'combined' log format, which includes standard information. You'll typically find your access logs in /var/log/nginx/access.log.
Here's what a common entry looks like:
192.168.1.1 - - [10/Oct/2023:14:30:00 +0000] "GET /index.html HTTP/1.1" 200 1234 "-" "Mozilla/5.0 (...)"Customizing Access Log Formats
Nginx allows you to define custom log formats using the log_format directive. This is powerful for tailoring logs to your specific monitoring or analysis needs.
You can include variables like $remote_addr (client IP), $request (full request line), $status (response status code), $body_bytes_sent, and many more.
Defining a Custom Log Format
Let's create a custom log format named 'my_json_format' that outputs logs in JSON. This is great for automated parsing!
Place this inside your http block in nginx.conf:
http {
log_format my_json_format escape=json
'{ "time_local":"$time_local",'
' "remote_addr":"$remote_addr",'
' "request":"$request",'
' "status":$status,'
' "bytes_sent":$body_bytes_sent,'
' "request_time":$request_time,'
' "http_referrer":"$http_referer",'
' "http_user_agent":"$http_user_agent" }';
server {
listen 80;
server_name example.com;
access_log /var/log/nginx/json_access.log my_json_format;
# ... other server config ...
}
}Understanding Error Logs
Error logs record diagnostic information about issues Nginx encounters, from configuration problems to backend connection failures.
They are crucial for debugging and maintaining server stability. You'll typically find them at /var/log/nginx/error.log.
Configuring Error Log Levels
The error_log directive allows you to specify the log file and the severity level. Nginx logs messages at or above the specified level.
- debug: Most verbose, for deep debugging.
- info: Informational messages.
- notice: Normal but significant conditions.
- warn: Potentially problematic situations.
- error: An error occurred.
- crit: Critical conditions.
- alert: Action must be taken immediately.
- emerg: System is unusable.
Setting Error Log Levels
You can configure the error log level globally in the main or http block, or specifically within a server or location block.
For production, warn or error is common to keep logs manageable. For debugging, you might temporarily set it to info or debug.
http {
error_log /var/log/nginx/error.log warn;
server {
listen 80;
server_name example.com;
# This server's errors will also be logged at 'warn' level
# You could override it here: error_log /path/to/server_error.log info;
}
}Log Rotation for Production
In production, logs can grow very large, very quickly. Log rotation is the process of archiving, compressing, and deleting old log files to prevent them from filling up your disk space.
While Nginx doesn't handle rotation itself, tools like logrotate (common on Linux) are used to manage this. You configure logrotate to periodically rotate Nginx's log files.
Nginx Log Metrics
Which of the following Nginx log variables would be most useful for calculating the average response time of your web application?
Recap: Logs for Insights
You've learned that Nginx access logs track client requests, while error logs report server issues. Customizing log formats with log_format allows you to tailor output for specific metrics or tools.
Understanding log levels (e.g., warn, error) helps control verbosity, and knowing about log rotation ensures disk space management.
These logging fundamentals are essential for effective monitoring and troubleshooting of your Nginx server.
자주 묻는 질문
“Nginx 로깅 및 지표” 강의는 무료인가요?
네 — “Nginx 로깅 및 지표” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 강의 전체를 잠금 해제할 수 있습니다. API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 강의에는 총 4개의 강의가 포함되어 있습니다.
“Nginx 로깅 및 지표”에서 뭘 배우나요?
Nginx 접근 로그와 오류 로그를 설정하고 모니터링 및 분석을 위해 지표를 추출하는 방법을 살펴보세요. 브라우저에서 직접 실행하는 실습 코드로 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.
“Nginx 로깅 및 지표” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- Nginx 로깅 및 지표
- Nginx 성능 조정
- 컨테이너 환경의 Nginx
- 무중단 다시 로드 및 구성 테스트