Apache Access log format and Logformat syntax

Source: Internet
Author: User
Tags apache access log

access log records every request from a user

Open the Apache master configuration file
vim /usr/local/apache2.4/conf/httpd.conf
主配置文件里提供了两种日志的模板:common和combined<IfModule log_config_module>LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combinedLogFormat "%h %l %u %t \"%r\" %>s %b" common
主配置文件里预设日志模板是commonCustomLog "logs/access_log" common
可以在虚拟主机里面更改日志模板<VirtualHost *:80>    DocumentRoot "/data/wwwroot/aaa.com"    ServerName aaa.com    ServerAlias www.aaa.com  www.abc.com    ErrorLog "logs/aaa.com-error_log"    CustomLog "logs/aaa.com-access_log" common</VirtualHost>//可以根据需求,把common改成combined
COMBINED Log Template
LogFormat "%h  %l  %u  %t  \"%r\"  %>s  %b  \"%{Referer}i\"  \"%{User-Agent}i\"" combined它记录的样子是这样的:59.126.205.242 - - [04/Jan/2009:23:30:57 +0800] "GET /main/images/login/login_05.png HTTP/1.1" 200 1355 "http://exmaple.com/i1.php?fun=login_show" "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-TW; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5 FirePHP/0.2.1"说明如下:1. 59.126.205.242 是客户端IP2. 第一个 ‘-‘ 是 %l 因为此网页不必认证,所以logname 为空3. 第二個 ‘-‘ 是 %u 因为此网页不必认证,所以username 为空4. [04/Jan/2009:23:30:57 +0800] 是时间5. "GET /main/images/login/login_05.png HTTP/1.1" 为客户端的 request6. 200  %s 是状态,%s 是取得最后的状丰收,数字200代表 OK7. 1355 排除掉 HTTP的headers后的长度(Bytes)8. "http://example.com/main/i1.php?fun=login_show" 记录 referer。也就是导到此request的页面的呼叫者,这里可以当来源分析。9. "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-TW; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5 FirePHP/0.2.1" 是客戶端的浏览器状态。

Apache Access log format and Logformat syntax

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.