預設 combined 格式對應:
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $custom_field';
122.59.14.12 122.59.14.12 - - [24/Apr/2011:10:37:06 +0800]
"GET /product/sellerscore.do?returnpage=0&supplierid=xxx HTTP/1.1"
499 0 "https://www.example.com/..." "Mozilla/4.0 ..." custom_value
| 欄位 | 範例值 | 變數 | 說明 |
|---|---|---|---|
| 1 | 122.59.14.12 | $remote_addr | 客戶端 IP |
| 2 | 122.59.14.12 | $remote_user | 認證使用者 (無則 -) |
| 3 | - | - | 佔位符 (identd) |
| 4 | - | - | 佔位符 (auth) |
| 5 | [24/Apr/2011:10:37:06 +0800] | $time_local | 請求時間 (東八區) |
| 6 | "GET /path?query HTTP/1.1" | $request | 請求行 (方法/路徑/協定) |
| 7 | 499 | $status | HTTP 狀態碼 (499=Nginx 專用:客戶端主動斷開) |
| 8 | 0 | $body_bytes_sent | 回應體位元組數 |
| 9 | "https://referer..." | $http_referer | 來源頁面 |
| 10 | "Mozilla/4.0..." | $http_user_agent | 客戶端 UA |
| 11 | custom_value | $custom_field | 自訂欄位 (如 session_id) |
499 Client Closed Request:Nginx 自定義狀態碼,表示客戶端在 Nginx 回應前主動關閉連線。常見於:用戶關閉瀏覽器、網路中斷、前端逾時設定過短、大檔案上傳取消。
ps aux | grep nginx | grep -v grep | wc -l
grep "24/Apr/2011" /var/log/nginx/access.log | wc -l
grep "24/Apr/2011" /var/log/nginx/access.log | grep "122.59.14.12" | awk '{print $7}'
grep "24/Apr/2011" /var/log/nginx/access.log | \
awk '{print $7}' | sort | uniq -c | sort -nr | head -10
grep "24/Apr/2011" /var/log/nginx/access.log | \
awk '{print $4}' | cut -c14-15 | sort | uniq -c | sort -nr | head
awk '{print $9}' /var/log/nginx/access.log | sort | uniq -c | sort -nr
awk '{print $1, $10}' /var/log/nginx/access.log | \
awk '{sum[$1]+=$2} END for (ip in sum) print sum[ip], ip' | sort -nr | head -10
# log_format 加入 $request_time
awk '$NF > 3 {print $0}' /var/log/nginx/access.log | head -20
goaccess -f access.log --log-format=COMBINED/var/log/nginx/*.log {
daily
missingok
rotate 30
compress
delaycompress
notifempty
create 0640 www-data adm
sharedscripts
postrotate
[ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
endscript
}