Apache 配置访问日志

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/li_haijiang/article/details/78831106

1、在主配置文件中定义日志格式

[root@localhost ~]# vim /usr/local/apache2/conf/httpd.conf
<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined  # 默认已定义好的日志格式,combined 是日志格式名
    LogFormat "%h %l %u %t \"%r\" %>s %b" common                                       # 默认已定义好的日志格式,common 是日志格式名
</IfModule>

2、在虚拟主机配置文件中应用日志格式

[root@localhost ~]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
    DocumentRoot "/data/www"
    ServerName www.test.com
    ErrorLog "logs/test.com_error_log"               
    CustomLog "logs/test.com_access_log" combined    # 这里应用 combined 格式的日志
</VirtualHost>

3、重新加载配置文件,访问站点并查看是否生成日志

[root@localhost ~]# /usr/local/apache2/bin/apachectl -t
[root@localhost ~]# /usr/local/apache2/bin/apachectl graceful
[root@localhost ~]# ls /usr/local/apache2/logs/    # 生成如下两个日志
access_log  error_log  httpd.pid  test.com_access_log  test.com_error_log

猜你喜欢

转载自blog.csdn.net/li_haijiang/article/details/78831106