Ris*_*hav 6 logging apache-2.4
我们得到了“PHP 耗尽了允许的内存”,其中 PHP 要求千兆字节的内存。如何格式化 Apache 错误日志以查看它正在访问哪个 URL?
接受的答案不会回答原始问题,因为它会记录到 access.log 而不是 error.log
您需要将 url 放在一个环境变量中,然后像这样从 ErrorLogFormat 调用它:
SetEnvIf Request_URI "(^.*$)" RURI=$1
ErrorLogFormat "%{cu}t %a %l %M URI:%{RURI}e"
Run Code Online (Sandbox Code Playgroud)
取自 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
Run Code Online (Sandbox Code Playgroud)
请参阅Apache 2 手册,了解不同格式符号 % 的含义,或参阅Apache 2 手册 ErrorlogFormat 指令,了解自 apache 2.4 以来的特定格式的错误日志。
简而言之 :
在主配置文件和输出文件中定义输出格式,例如 VirtualHost 指令中的每个虚拟主机。如果需要,您也可以在主文件中定义所有站点的配置文件。
需要添加类似的东西(如果它还没有):
LogLevel warn
CustomLog /var/log/apache2/access.log combined
ErrorLog /var/log/apache2/error.log
Run Code Online (Sandbox Code Playgroud)
根据您的具体设置,您可能需要稍微更改位置。
如果您的网站流量较高,请不要忘记对它们进行日志轮换。
通常这应该是(至少在 debian 中)我记忆的默认设置。
如果您有空日志,您可能需要检查文件夹/文件的权限,以便运行 apache2 进程的用户可以访问和写入它们。
请记住(据我所知)重新读取配置文件需要重新加载进程。
归档时间: |
|
查看次数: |
4431 次 |
最近记录: |