Web sunucusu olarak çoğunlukla tercih edilen sunucular apache veya ngnix’dir. Access log’ların formatları isteğe göre düzenlebilir fakat;
Access.log format olarak nginx’de varsayılan “combined” adlı aşağıda belirtilen biçimi kullanıyorsanız:
1 2 |
$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" |
$remote_addr : İstek yapılan IP
$remote_user: HTTP doğrulanmış kullanıcı. Bu çoğu uygulamalar için boş olacaktır.
[$time_local] : Sunucu zaman dilimi damgası
“$request”: HTTP istek tipi GET, POST, vb + args olmadan istenen yol + HTTP protokol sürümü
$status : Sunucudan dönen HTTP yanıt kodu
$body_bytes_sent: bayt sunucu yanıt boyutu
“$http_referer” : HTTP protokolünde yönlendirmeyi yapan sayfanın bilgisini iletir (varsa)
“$http_user_agent”: Sunucu tarafından görülen kullanıcı aracısı
Sayfa Kodları
200 – OK
206 – Partial Content
301 – Moved Permanently
302 – Found
304 – Not Modified
401 – Unauthorised (password required)
403 – Forbidden
404 – Not Found
Sunucudan dönen HTTP yanıt kodu’na göre sıralama
1 |
cat access.log | cut -d '"' -f3 | cut -d ' ' -f2 | sort | uniq -c | sort -r |
1 2 3 4 5 |
[root@blog /var/log/nginx]$cat access.log | cut -d '"' -f3 | cut -d ' ' -f2 | sort | uniq -c | sort -r 1 403 139 301 139 200 [root@blog /var/log/nginx]$ |
aynı işlemi awk kullanarak yapabiliriz:
1 |
awk '{print $9}' access.log | sort | uniq -c | sort -r |
404 HTTP yanıt Koduna sahip, yani olmayan bağlantıları tespit etmek için
404 ile sonuçlanan istekleri, URL ve sayısına göre sıralamak için:
1 |
awk '($9 ~ /404/)' access.log | awk '{print $7}' | sort | uniq -c | sort -r |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
[root@blog /mnt/httplogs/nginx]$awk '($9 ~ /404/)' access.log | awk '{print $7}' | sort | uniq -c | sort -r 8 /apple-touch-icon-precomposed.png 7 /apple-touch-icon.png 1 /templets/default/style/dedecms.css 1 /templates/cn/template.xml 1 /template/default/common/footer.htm 1 /js/transport.js 1 /_fckeditor/fckeditor.js 1 /comments/feed/ 1 /avrupa/bulgaristan/sofya/sofya-nasil-bir-sehirdir 1 /avrupa/avusturya/viyana/viyanada-nazil-gezilir 1 /asya/tayland/bangkok-tayland/www.bangkokairport.com 1 /apple-touch-icon-120x120-precomposed.png 1 /apple-touch-icon-120x120.png 1 /Administrator/FCKeditor/fckeditor.js 1 /Administrator/fckeditor/fckeditor.js 10 /robots.txt |
Benzer şekilde 502(bad-gateway) için:
1 |
awk '($9 ~ /502/)' access.log | awk '{print $7}' | sort | uniq -c | sort -r |
İstenmeyen erişimleri tespit etmek için:
1 2 |
[root@blog /mnt/httplogs/nginx]$awk -F\" '($2 ~ "/wp-admin/install.php"){print $1}' access.log | awk '{print $1}' | sort | uniq -c | sort -r 1 212.156.51.102 |
PHP dosyaları için 404’leri tespit etmek için:
1 |
awk '($9 ~ /404/)' access.log | awk -F\" '($2 ~ "^GET .*\.php")' | awk '{print $7}' | sort |uniq -c | sort -r | head -n 20 |
1 2 3 4 5 6 |
[root@blog /mnt/httplogs/nginx]$awk '($9 ~ /404/)' access.log | awk -F\" '($2 ~ "^GET .*\.php")' | awk '{print $7}' | sort |uniq -c | sort -r | head -n 20 2 /aaaaaaaaaaaa.php 1 /ssss.php 1 /11wwwwwwwww11.php 1 /11wwww11.php 1 /1111.php |
En çok istek yapılan URL’ler:
1 |
awk -F\" '{print $2}' access.log | awk '{print $2}' | sort | uniq -c | sort -r |
En çok istek yapılan içeriğinde “xyz” olan URL’ler:
1 |
awk -F\" '($2 ~ "xyz"){print $2}' access.log | awk '{print $2}' | sort | uniq -c | sort -r |