LAMP 架构——Apache 访问日志

Apache 日志位置

[root@dl-001 ~]# ls /usr/local/apache2.4/logs/
111.com-access_log  abc.com-access_log  access_log  httpd.pid
111.com-error_logo  abc.com-error_log   error_log

查看日志格式

[root@dl-001 ~]# vim /usr/local/apache2.4/conf/httpd.conf    //打开主配置文件(搜索 /Log)
<IfModule log_config_module>
    #
    # The following directives define some format nicknames for use with
    # a CustomLog directive (see below).
    #
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

说明:combined 和 common 两种格式,默认使用 common 格式。


####common 格式的日志

[root@dl-001 ~]# cat /usr/local/apache2.4/logs/111.com-access_log 
192.168.36.128 - - [19/Dec/2017:23:16:23 +0800] "GET HTTP://www.example.com/ HTTP/1.1" 200 7
192.168.66.128 - - [20/Dec/2017:22:44:18 +0800] "HEAD HTTP://111.com/ HTTP/1.1" 401 -
192.168.66.1 - - [20/Dec/2017:22:44:36 +0800] "GET / HTTP/1.1" 401 401
192.168.66.1 - dl [20/Dec/2017:22:44:48 +0800] "GET / HTTP/1.1" 500 535
192.168.66.1 - - [20/Dec/2017:22:44:57 +0800] "GET / HTTP/1.1" 401 401
192.168.66.1 - dl [20/Dec/2017:22:45:22 +0800] "GET / HTTP/1.1" 500 535
192.168.66.1 - dl [20/Dec/2017:22:45:25 +0800] "GET / HTTP/1.1" 500 535
192.168.66.1 - dl [20/Dec/2017:22:45:32 +0800] "GET / HTTP/1.1" 500 535

更改 log 的格式为 combined

1. 修改配置文件

[root@dl-001 ~]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
    ErrorLog "logs/111.com-error_logo"
    CustomLog "logs/111.com-access_log" combined    //默认使用common格式改为combined格式

2. 重新加载

[root@dl-001 wwwroot]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@dl-001 wwwroot]# /usr/local/apache2.4/bin/apachectl graceful

3. 查看日志变化 (可以进行一些操作,然后查看 log,结果显而易见)

[root@dl-001 ~]# cat /usr/local/apache2.4/logs/111.com-access_log 
192.168.66.128 - - [21/Dec/2017:00:21:53 +0800] "HEAD HTTP://www.example.com/ HTTP/1.1" 301 - "-" "curl/7.29.0"
192.168.66.128 - - [21/Dec/2017:00:22:11 +0800] "HEAD HTTP://www.example.com/ HTTP/1.1" 301 - "-" "curl/7.29.0"
192.168.66.128 - - [21/Dec/2017:00:22:21 +0800] "HEAD HTTP://www.example.com/ HTTP/1.1" 301 - "-" "curl/7.29.0"
192.168.66.128 - - [21/Dec/2017:00:22:21 +0800] "HEAD HTTP://www.example.com/ HTTP/1.1" 301 - "-" "curl/7.29.0"
192.168.66.128 - - [21/Dec/2017:00:22:22 +0800] "HEAD HTTP://www.example.com/ HTTP/1.1" 301 - "-" "curl/7.29.0"