我们正在获取“允许的PHP内存耗尽”,PHP要求提供千兆字节的内存。 我如何格式化Apache错误日志来查看它正在访问哪个URL?
取自debian apache2.conf的默认文件:
# The following directives define some format nicknames for use with # a CustomLog directive (see below). # If you are behind a reverse proxy, you might want to change %h into %{X-Forwarded-For}i # LogFormat "%v:%p %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %b" common LogFormat "%{Referer}i -> %U" referer LogFormat "%{User-agent}i" agent
有关不同格式标记%或Apache 2 Manual ErrorlogFormat指令的含义,请参阅“ Apache 2手册” ,以了解Apache 2.4以来的特定格式的错误日志。
简而言之 :
在主configuration文件中定义输出格式,在VirtualHost指令中定义输出文件,例如每个虚拟主机的输出文件。 如果你愿意,你也可以在主文件中定义你所有站点的configuration文件。
需要添加一些东西(如果还没有的话):
LogLevel warn CustomLog /var/log/apache2/access.log combined ErrorLog /var/log/apache2/error.log
根据您的确切设置,您可能需要稍微更改位置。
不要忘记login如果你有一个高stream量的网站。
通常这应该是(至less在debian中)我如何记住它的默认设置。
如果你有空的日志,你可能想要检查文件夹/文件的权限,以便apache2进程运行的用户可以访问并写入它们。
请记住重新读取configuration文件所需的进程重新加载(据我所知)。
接受的答案不会回答原来的问题,因为它logging到access.log而不是error.log
你需要把url放在一个环境variables中,然后像下面这样从ErrorLogFormat中调用它:
SetEnvIf Request_URI "(^.*$)" RURI=$1 ErrorLogFormat "%{cu}t %a %l %M URI:%{RURI}e"