Home > Article > Backend Development > Play with Nginx logs purely manually
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>
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 < 100) print $3″|”$4″|”$11″|”$6}'
tail -f access.log | cat -e
or
tail -f access.log | tr '^A' '|'
The above is an introduction to manually playing with Nginx logs, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.