nginx
and,
Syntax
access_log path [format]; error_log path [level];
Parameters
| Parameters | Description | Examples | Level |
|---|---|---|---|
access_log |
access_log /var/log/nginx/access.log; |
Common | |
error_log |
and Level | error_log /var/log/nginx/error.log warn; |
Common |
log_format |
log_format main '...'; |
Common | |
access_log off |
access_log off; |
Advanced |
Examples
JSON
log_format json_log escape=json '{
"time": "$time_iso8601",
"remote_addr": "$remote_addr",
"request": "$request",
"status": $status,
"body_bytes_sent": $body_bytes_sent,
"request_time": $request_time,
"upstream_response_time": "$upstream_response_time"
}';
access_log /var/log/nginx/access.json json_log;ELK and more
server {
server_name api.example.com;
access_log /var/log/nginx/api.access.log;
error_log /var/log/nginx/api.error.log;
}location ~* \.(css|js|jpg|png|gif|ico)$ {
access_log off;
expires 30d;
},
Common Errors
logrotate : /etc/logrotate.d/nginx
Tips
- JSON,
- error_log Level: debug, info, notice, warn, error, crit
- logrotate,