在浏览器中访问了某网站,或者在网站页面执行了某些命令,会被记录在访问日志中(log)。默认的log目录为/Apache/log/
1.通过配置文件了解访问日志
vim /usr/local/apache2.4/conf/httpd.conf //查找LogFormat内容 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 //%h表示来源ip,%l表示login的用户,%u表示用户,%t表示时间,%r表示行为(get或者head),%s表示状态码,%b表示的大小,%{Referer}i表示浏览器上一次访问的地址,%{User-Agent}i表示访问时使用的方式
2.配置虚拟主机文件
vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf <VirtualHost *:80> ServerAdmin webmaster@dummy-host.example.com DocumentRoot "/usr/local/apache2.4/docs/111.com" ServerName www.111.com ServerAlias 111.com ErrorLog "logs/abc.com-error_log" CustomLog "logs/abc.com-access_log" combined </VirtualHost> /usr/local/apache2.4/bin/apachectl -t /usr/local/apache2.4/bin/apachectl graceful
3.通过curl和网页访问查看访问日志的变化
[root@antong extra]# curl -xlocalhost:80 -I 123.com HTTP/1.1 301 Moved Permanently Date: Wed, 04 Aug 2021 17:42:42 GMT Server: Apache/2.4.33 (Unix) PHP/5.6.30 Location: http://111.com/ Content-Type: text/html; charset=iso-8859-1 [root@antong ~]# tail -n 1 /usr/local/apache2.4/logs/abc.com-access_log ::1 - - [04/Aug/2021:13:45:40 -0400] "HEAD HTTP://123.com/ HTTP/1.1" 301 - "-" "curl/7.29.0" //使用电脑浏览器访问Apache的地址 [root@antong ~]# tail -n 1 /usr/local/apache2.4/logs/abc.com-access_log 192.168.200.1 - - [04/Aug/2021:13:47:03 -0400] "GET / HTTP/1.1" 301 223 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36"