s %b \"%{Re_apache日志配置">
当前位置:   article > 正文

Apache相关配置----日志管理_apache日志配置

apache日志配置

Apache配置----日志管理

Apache日志位置 /usr/local/apache2/logs/

1.检查日志模块是否开启

vi /usr/local/apache2/conf/httpd.conf
1)搜索:/log_config
检查该模块是否开启(默认开启)
2)查看日志相关格式规定
搜索:/LogFormat
#就可以看到以下内容(%h 是来源ip;%u是访问user;%t是时间;%r是动作)
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

2.修改配置文件,进行日志管理

vi /usr/local/apache2/conf/extra/httpd-vhosts.conf
  • 1

(1)日志切割与管理

# Web服务器会出现大量的访问日志和错误日志,所以我们要对日志进行切割,方便管理查询。
# 在<VirtualHost>标签内添加如下内容
CustomLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/007.com-access_%Y%m%d_log 86400" combined
# 1-1.重启httpd服务
/usr/local/apache2/bin/apachectl  restart
# 1-2.修改时间进行测试
date 04040000         #4月4日
curl ip
data 04050000         #4月5日
curl ip
# 1-3.查看日志是否产生
ls /usr/local/apache2/logs/
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

(2)不记录指定文件类型的日志

# 网站上的图片,还有 js,css 等静态对象。用户对它们的访问往往是巨大的,记录这些日志也没什么用,那就可以不记录这些。
# 在<VirtualHost>标签内添加如下内容
ErrorLog "logs/007.com-error_log"
SetEnvIf Request_URI ".*\.gif$" image-request
SetEnvIf Request_URI ".*\.jpg$" image-request
SetEnvIf Request_URI ".*\.png$" image-request
SetEnvIf Request_URI ".*\.bmp$" image-request
SetEnvIf Request_URI ".*\.swf$" image-request
SetEnvIf Request_URI ".*\.js$" image-request
SetEnvIf Request_URI ".*\.css$" image-request
CustomLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/007.com-access_%Y%m%d_log 86400" combined env=!image-request
# 不记录做过标记的文件
# 2-1.检查配置文件是否有语法错误
/usr/local/apache2/bin/apachectl -t
# 2-2.如果没错就重新启动httpd服务
/usr/local/apache2/bin/apachectl  restart
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

感谢大家,点赞,收藏,关注,评论!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/黑客灵魂/article/detail/810902
推荐阅读
相关标签
  

闽ICP备14008679号