首页  >  文章  >  运维  >  Apache服务器要记录日志怎么办

Apache服务器要记录日志怎么办

(*-*)浩
(*-*)浩原创
2019-11-27 15:09:292890浏览

Apache服务器要记录日志怎么办

Apache服务器日志提供有助于检测服务器常见问题的详细信息。要记录网站的访问日志,必须启用mod_log_configmodule。

apache配置文件中有三个指令,即 -

TransferLog:创建日志文件。           ( 推荐学习:Apache服务器 )

LogFormat:指定自定义格式。

CustomLog:创建和格式化日志文件。

TransferLog指令在apache配置文件中可用,它根据设置参数轮转虚拟主机日志文件。

VirtualHost www.example.com><br/><br/>  ServerAdmin webmaster@yiibai.com<br/>  DocumentRoot /usr/www/example/httpd/htdocs/<br/>  ServerName www.example.com<br/>  ServerAlias example.com www.example<br/>  ErrorLog /usr/www/example/httpd/logs/error_log<br/>  TransferLog /usr/www/example/httpd/logs/accesslog<br/>  CustomLog /usr/www/example/httpd/logs/accesslog combined<br/><br/></VirtualHost><br/>

两种类型的Apache日志格式

通用日志格式

组合日志格式

可以通过编辑apache配置文件来启用它们,即apache2.conf(Debian/ubuntu)或httpd.conf(基于rpm的系统)文件。

通用日志格式

LogFormat "%h %l %u %t \"%r\" %>s %b" common<br/>CustomLog logs/access_log.log common<br/>

Apache生成的通用日志内容示例如下 

[Wed Oct 11 14:32:52 2000] [error] [client 127.0.0.1] client denied by server configuration: /export/home/live/ap/htdocs/test<br/>

组合日志格式

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined<br/>CustomLog log/access_log.log combined<br/>

在上面格式中,

%h是远程主机

%l是由identd确定的用户的身份

%u是HTTP身份验证确定的用户名

%t是服务器处理完请求的时间。

%r是来自客户端的请求行(“GET/HTTP/1.0”)。

%> s是从服务器发送到客户端的状态代码(500,404等)

%b是客户端响应的大小(以字节为单位)Referer是链接到此URL的页面。

用户代理是浏览器标识字符串。

Apache生成的组合日志:

199.180.11.91 - - [06/Mar/2019:04:22:58 +0100] "GET /robots.txt HTTP/1.1" 404 1228 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)"<br/>

自定义日志为服务器上的每个虚拟主机创建单独的日志文件。它需要在配置文件的虚拟主机部分中指定。

可以看到下面提到的虚拟主机配置,生成的日志将为该虚拟主机自定义,并且将组合格式。

apache-6.jpg

以上是Apache服务器要记录日志怎么办的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn