|
我在服務(wù)器上有每天切割nginx日志的習(xí)慣,所以針對每天各大搜索引擎來訪,總能記錄一些404頁面信息,傳統(tǒng)上我只是偶爾分析下日志,但是對于很多日志信息的朋友,人工來篩選可能不是一件容易的事情,這不我個人自己慢慢研究了一點點,針對谷歌、百度、搜搜、360搜索、宜搜、搜狗、必應(yīng)等搜索引擎的404訪問生成為一個txt文本文件,直接上代碼test.php。
復(fù)制代碼 代碼如下:
<?php
//訪問test.php?s=google
$domain='http://www.jb51.NET';
$spiders=array('baidu'=>'Baiduspider','360'=>'360Spider',
'google'=>'Googlebot','soso'=>'Sosospider','sogou'=>
'Sogou web spider','easou'=>'EasouSpider','bing'=>'bingbot');
$path='/home/nginx/logs/'.date('Y/m/').(date('d')-1).'/access_www.txt';
$s=$_GET['s'];
if(!array_key_exists($s,$spiders)) die();
$spider=$spiders[$s];
$file=$s.'_'.date('ym').(date('d')-1).'.txt';
if(!file_exists($file)){
$in=file_get_contents($path);
$pattern='/GET (.*) HTTP//1.1" 404.*'.$spider.'/';
preg_match_all ( $pattern , $in , $matches );
$out='';
foreach($matches[1] as $k=>$v){
$out.=$domain.$v."/r/n";
}
file_put_contents($file,$out);
}
$url=$domain.'/silian/'.$file;
echo $url;
好就這樣了。沒有什么高深的技術(shù),只有動手寫的過程。
php技術(shù):PHP統(tǒng)計nginx訪問日志中的搜索引擎抓取404鏈接頁面路徑,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。