Rob*_*anu 6 logwatch apache-2.2
当使用 apache 托管多个域时,查看包含虚拟主机名的 logwatch apache 输出很有用,但我只得到:
--------------------- httpd Begin ------------------------
Requests with error response codes
400 Bad Request
/: 1 Time(s)
/robots.txt: 1 Time(s)
Run Code Online (Sandbox Code Playgroud)
而我想要类似的东西
--------------------- httpd Begin ------------------------
Requests with error response codes
400 Bad Request
example.com/: 1 Time(s)
example.org/robots.txt: 1 Time(s)
Run Code Online (Sandbox Code Playgroud)
如何使用 logwatch 实现这一目标?
小智 3
试试这个(对我有用):在你的httpd.conf
as中定义 LogFormat
LogFormat "%h %t [%V] \"%r\" %>s \"%{Referer}i\""
在这种特殊情况下,您将拥有远程地址、日期/时间、[根据 UseCanonicalName 设置的服务器名称]、请求、状态代码和引用者(这是我想要的格式),然后输入
$LogFormat "%h %t %V \"%r\" %>s \"%{Referer}i\""
在 services/http.conf LogWatch 文件中。那将
以下是日志输出中包含这组特定指令的行的示例:
172.3.20.11 [01/Jun/2011:21:00:52 +0200] joomla.local“GET /images/tabs_back.png HTTP/1.1”404“ http://joomla.local/templates/beez_20/css/personal .css "
如果我们关注错误代码,以及 LogWatch 中如何处理它们,您可以对/usr/share/logwatch/scripts/services/http进行一些更改: 添加:
我的 $my_host = ""; 我的 $my_url = "";
然后,在第 462 行,添加此行以保存我们的第四列(主机):
$field{my_host} = $field{$log_fields[3]};
在第560行,在fmt_url
short( if (length($field{url}) > 60) {...}
)之后添加:
$my_host = $field{$log_fields[3]};
$my_host = substr($my_host,1);
$my_url=$my_host . $fmt_url;
Run Code Online (Sandbox Code Playgroud)
最后,改变:
$needs_exam{$field{http_rc}}{$fmt_url}++;
经过
$needs_exam{$field{http_rc}}{$my_url}++;
这样做,您的 Logwatch 中将会出现以下内容:
Requests with error response codes
404 Not Found
joomla.local/images/tabs_back.png: 3 Time(s)
Run Code Online (Sandbox Code Playgroud)
我希望它能帮助大家
归档时间: |
|
查看次数: |
3921 次 |
最近记录: |