分享好友 系统运维首页 频道列表

apache日志:error_log,access_log

apache教程  2023-02-10 02:350

参考资料

apache开启日志记录,access.log

Apache配置文件里的LogLevel指令说明

apache官方文档 apache logs

关于error log

今天在一台测试服务器上测试项目时,有一个请求返回了500状态码,web服务器使用的是apache,于是就查找apache错误日志,却发现日志是空的.好奇怪.

后来查资料,发现,错误记录也是有级别的

Level Description Example
emerg Emergencies - system is unusable.紧急状况;服务器无法使用  "Child cannot open lock file. Exiting"
alert Action must be taken immediately.必须立刻采取动作 "getpwuid: couldn't determine user name from uid"
crit Critical Conditions.危急状况 "socket: Failed to get a socket, exiting child" 
error Error conditions.出现错误  "Premature end of script headers"
warn Warning conditions.警告 "child process 1234 did not exit, sending another SIGHUP" 
notice Normal but significant condition.正常,但有情况要注意  "httpd: caught SIGBUS, attempting to dump core in ..."
info Informational.普通信息  "Server seems busy, (you may need to increase StartServers, or Min/MaxSpareServers)..."
debug Debug-level messages.调试级别信息,包括模块运行状态 "Opening config file ..."
   

这个错误级别记录在apache的配置文件httpd.conf或者虚拟主机配置文件中

ErrorLog "logs/error_log"

#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel alert

其中,LogLevel就指定了最低要记录的错误级别,我公司这台测试服务器原来的级别是alert,太高了,导致很多错误不会记录,因此我设置为info,重启apache,然后重现错误,终于在error_log中发现了错误原因:

[Tue Jul 25 17:33:06.476703 2017] [:error] [pid 2316:tid 3328] [client 113.47.63.8:49522] PHP Fatal error:  
Call to undefined function Awap\\Controller\\getLogger() in 项目路径\\Application\\Awap\\Controller\\AdvertiserController.class.php on line 533,
referer: http://www.xxxx.com/Awap/Advertiser/register

 

原来是php报了错,后来追项目的源码,发现是php返回了500的状态码.

那为什么apache 的error_log会记录PHP的错误呢,apache文档中是这样说的:

The error log will also contain debugging output from CGI scripts. 
Any information written to stderr by a CGI script will be copied directly to the error log.

意思是:php作为一个CGI脚本,它的标准错误(stderr)被复制了一份放在了apache error log中.

apache推荐最低级别为crit,具体设置为哪个,还是根据自己的需求来设定吧!

 

关于access_log

以下是我的笔记,大概记录了一下,详情请查看文章头部的链接

Related Modules:mod_log_config mod_setenvif

Related Directives:CustomLog LogFormat SetEnvIf

access log的作用:access log记录了所有服务器处理过的请求.

access log的存放路径和内容由 CustomLog指令控制,

使用LogFormat指令可以简单地指定在内容中需要显示的项目,

举例,下面代码中的黄色区域,CustomLog指定了access log的存放路径

<VirtualHost *:80>
    LogLevel info
    DocumentRoot "E:\qprwork\project"
    ErrorLog "logs/myapp.com-error.log"   
    CustomLog "logs/myapp.com-access.log" combined
    ServerName myapp.com
    <Directory   "E:\qprwork\project">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
    
</VirtualHost>

那个combined是啥?他是告诉log的记录格式的.这个就和LogFormat有关了

LogFormat指令分为两部分,第一部分是格式,第二部分为nickname,

 

以下摘自httpd.conf,蓝色就是LogFormat,其中左侧百分号那一串是格式,右侧combined是nickname

<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

    <IfModule logio_module>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    #
    # The location and format of the access logfile (Common Logfile Format).
    # If you do not define any access logfiles within a <VirtualHost>
    # container, they will be logged here.  Contrariwise, if you *do*
    # define per-<VirtualHost> access logfiles, transactions will be
    # logged therein and *not* in this file.
    #
    CustomLog "e:/wamp/logs/access.log" common

    #
    # If you prefer a logfile with access, agent, and referer information
    # (Combined Logfile Format) you can use the following directive.
    #
    #CustomLog "logs/access.log" combined
</IfModule>

在定制CustomLog时,可以使用nickname指定需要的格式,如上面代码片段中的 CustomLog "logs/myapp.com-access.log"   combined 

以下是apache的access_log片段

127.0.0.1 - - [25/Jul/2017:22:42:06 +0800] "GET /advertiser/index/monolog HTTP/1.1" 200 195 "-" 
"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36" 127.0.0.1 - - [25/Jul/2017:22:42:06 +0800] "GET /favicon.ico HTTP/1.1" 200 1150 "http://myapp.com/advertiser/index/monolog"
"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36"

 

查看更多关于【apache教程】的文章

展开全文
相关推荐
反对 0
举报 0
评论 0
图文资讯
热门推荐
优选好物
更多热点专题
更多推荐文章
Hadoop中mapreduce运行WordCount程序报错Error: java.io.IOException: Type mismatch in key from map: expected o
这个问题是因为map的方法参数与继承mapper定义的参数类型不一致导致的,应该将Mapper的key参数类型设置成Object,就可以解决这个问题 

0评论2023-03-08965

[转]用apache反向代理解决单外网ip对应内网多个web主机的问题
用apache反向代理解决单外网ip对应内网多个web主机的问题  转载一个有独立外网IP,需内网服务器对外发布的例子,是应用apache虚拟主机的。来源地址:http://www.itshantou.com/Servers/web/06/10/44219.html    几年前开始在学校的服务器上建网站,那时

0评论2023-02-10583

Apache service named reported the following error(OS 10055)由于系统缓冲区空间不足或队列已满解决办法?
apache启动失败报错:The Apache service named reported the following error: AH00451: no listening sockets available, shutting down . The Apache service named reported the following error: (OS 10055)由于系统缓冲区空间不足或队列已满,不能执行

0评论2023-02-10403

struts布局管理---SiteMesh一个优于Apache Tiles的Web页面布局、装饰框架
1. SiteMesh的基本原理       一个请求到服务器后,如果该请求需要sitemesh装饰,服务器先解释被请求的资源,然后根据配置文件 获得用于该请求的装饰器,最后用装饰器装饰被请求资源,将结果一同返回给客户端浏览器。 2. 如何使用SiteMesh    这里以st

0评论2023-02-10726

linux 安装 apache2.2.31
 Linux下安装和配置Apache 概要:本文介绍在CentOS5.4 Linux中安装和配置Apache2.2.14,并且实现Apache和Tomcat6的整合。文章分为三部分,分别是删除系统自带的Apache、安装Apache2.2.14和配置Apache2.2.14。 文章中介绍的知识也可以在其它版本的Linux中

0评论2023-02-10408

apache下ab.exe使用方法。。 apache ab工具
自己在cmd中写了半天的路径也没有写对。。最后网上的一个哥们告诉我说没有共同语言了。。。毛线啊 差距确实很大!大能猫死panda早晚干掉你,叫你丫整天嘲讽我!比如我的ab.exe在D盘的wamp文件夹下apache文件夹下bin文件夹下。那么在cmd中可以这么写:"D:\wamp

0评论2023-02-10478

CentOS 下的apache服务器配置与管理
一、WEB服务器与Apache1、web服务器与网址2、Apache的历史3、补充http://www.netcraft.com/可以查看apache服务器的市场占有率同时必须注意的是ngnix,正处于强势增长的上升时期,大有和apache一争天下的感觉,真是后生可畏~~~二、Apache服务器的管理命令1、命

0评论2023-02-10950

apache 的FTPClient使用以及注意事项
      tomcat+apache+jk进行集群后,图片要进行共享,经过网上的搜索可以有多种方式实现。        一种是使用jcifs。jcifs可以实现网络***享文件的读写,但是前提是,文件必须共享,还要在同一个局域网内。所以如果电脑上禁止了文件共享的话,就

0评论2023-02-10427

apache错误02:安装完后,系统找不到指定的文件 No installed service named "Apache2"的解决办法
解决办法:在“开始 -〉运行”处输入 cmd 回车,转到apache的安装目录,然后进入bin 目录,即cd bin ,在这里敲入 apache.exe -k install 后回车,然后重启Apache 就OK了。

0评论2023-02-10851

Apache提示You don't have permission to access / on this server 解决
 ;建议针对/private/var/log/apache2/中error来看[Sun Jun 02 18:00:37.760853 2019] [core:error] [pid 1677] (13)Permission denied: [client 127.0.0.1:53454] AH00035: access to / denied (filesystem path ‘/Users/sf/Documents/phpstorm’) because

0评论2023-02-10912

windows Apache 配置支持HTTPS的SSL证书
在设置Apache + SSL之前, 需要做:安装Apache, 下载安装Apache时请下载带有ssl版本的Apache安装程序.并且ssl需要的文件在如下的位置:     [Apache安装目录]/modules/ mod_ssl.so    [Apache安装目录]/bin/ openssl.exe, libeay32.dll, ssleay32.dll, ope

0评论2023-02-10924

mysql_pconnect的水挺深,apache下的数据库长连接
  php的mysql持久化连接,美好的目标,却拥有糟糕的口碑,往往令人敬而远之。这到底是为啥么。近距离观察后发现,这家伙也不容易啊,要看apache的脸色,还得听mysql指挥。  对于做为apache模块运行的php来说,要实现mysql持久化连接,首先得取决于apache这个

0评论2023-02-10314

网页504超时 apache php
1. 修改apache 配置apache-default.conf  timeout设置成12002. 修改php.ini 配置php.inimax_execution_time = 1200max_input_time = 1200max_execution_time = 1200 后来发现还没有解决问题,到60s就超时了排查到合作的一个代理https的服务器,他们默认60s

0评论2023-02-10635

更多推荐