LAMP结构-访问日志

查看日志

cat /usr/local/apache2.4/logs/szl.com-access_log

查看日志两种模式

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(默认);

其中变量代表意思
h:访问ip
l:用户
u:用户名
t:时间
r:行为和网址
s:状态码
b:大小
Referer:
User-Agent:用户代理内容,例如浏览器;

更改日志记录情况

vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
将CustomLog "logs/szl.com-access_log" 后面的common修改为combined
<VirtualHost *:80>
    DocumentRoot "/data/wwwroot/szl.com"
    ServerName szl.com
    ServerAlias www.example.comwww.szl.com
    <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteCond %{HTTP_HOST} !^szl.com$
      RewriteRule ^/(.*)$ http://szl.com/$1 [R=301,L]
    </IfModule>
    ErrorLog "logs/szl.com-error_log"
    CustomLog "logs/szl.com-access_log" combined
</VirtualHost>

更新配置

/usr/local/apache2.4/bin/apachectl -t
/usr/local/apache2.4/bin/apachectl graceful

使用浏览器访问一次szl.com/admin.php ,产生一条日志;

查看最新日志

由于更改成了combined,显示比common将更加多;

cat /usr/local/apache2.4/logs/szl.com-access_log
192.168.188.1 - - [03/Mar/2018:00:17:27 +0800] "GET /admin.php HTTP/1.1" 200 9 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.104 Safari/537.36 Core/1.53.4549.400 QQBrowser/9.7.12900.400"

使用curl服务器本机测试

curl -x127.0.0.1:80 -l szl.com
tail /usr/local/apache2.4/logs/szl.com-access_log

127.0.0.1 - - [03/Mar/2018:00:29:58 +0800] "GET HTTP://szl.com/ HTTP/1.1" 200 7 "-" "curl/7.29.0"