access_log <span>/</span>data<span>/</span>logs<span>/</span>nginx<span>-</span>access<span>.</span><span>log</span><span>;</span>log_format old <span><em>'$remote_addr [$time_local] $status $request_time $body_bytes_sent '</em></span><span><em>'"$request" "$http_referer" "$http_user_agent"'</em></span><span>;</span>
access_log <span>/</span>data<span>/</span>logs<span>/</span>nginx<span>-</span>access<span>.</span><span>log</span> buffer<span>=</span><span><em>32k</em></span> flush<span>=</span><span><em>5s</em></span><span>;</span>
log_format new <span><em>'$remote_addr^A$http_x_forwarded_for^A$host^A$time_local^A$status^A'</em></span><span><em>'$request_time^A$request_length^A$bytes_sent^A$http_referer^A$request^A$http_user_agent'</em></span><span>;</span>
這樣之後就透過常見的 Linux 命令列工具進行分析了:
cat access.log | awk -F ‘^A’ ‘{print $10}’ | sort | uniq -c
cat access.log | awk -F ‘^A’ ‘{if($5 == 500) print $0}’
cat access.log | awk -F ‘^A’ ‘{if($5 == 500) print $0}’ | wc -l
cat access.log | awk -F ‘^A’ ‘{if($5 == 500) print $0}’ | grep ’09:00’ | wc-l
tail -f access.log | awk -F ‘^A’ ‘{if($6>1) print $0}’
tail -f access.log | awk -F ‘^A’ ‘{if($6>1) print $3″|”$4}’
cat access.log | awk -F ‘^A’ ‘{if($5==502) print $11}’ | sort | uniq -c
cat access.log | awk -F ‘^A’ ‘{if($5==200 && $8
查看即時日誌資料流tail -f access.log | cat -e
以上就介紹了純手工玩轉 Nginx 日誌,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。