在Apache2.4中,我需要尽可能多地记录导致400错误的请求。是否可以在不将日志记录级别设置为debug的情况下实现这一点?是否也可以只记录400个错误,而不记录任何其他4XX?谢谢你,谢谢将日志记录级别设置为debug可能会起作用,但它会记录太多的错误(404,403 ...),我不需要这样做
debug
fruv7luv1#
将/tmp/400errors.log更改为要记录输出的位置
/tmp/400errors.log
在apache中使用SetEnvIf将此添加到httpd.conf
SetEnvIf
httpd.conf
# Set an environment variable for 400 series errorsSetEnvIfNoCase Response_Status "^400" LOG_400_ERRORS# Define a custom log format that includes the error statusLogFormat "%h %l %u %t \"%r\" %>s \"%{Referer}i\" \"%{User-Agent}i\"" combined_with_status# Use conditional logging based on the environment variableCustomLog /tmp/400errors.log combined_with_status env=LOG_400_ERRORS
# Set an environment variable for 400 series errors
SetEnvIfNoCase Response_Status "^400" LOG_400_ERRORS
# Define a custom log format that includes the error status
LogFormat "%h %l %u %t \"%r\" %>s \"%{Referer}i\" \"%{User-Agent}i\"" combined_with_status
# Use conditional logging based on the environment variable
CustomLog /tmp/400errors.log combined_with_status env=LOG_400_ERRORS
在apache中使用mod_rewrite,无论是在你的站点配置,还是htaccess文件中
mod_rewrite
RewriteEngine On# Redirect 400 series errors to a custom error logRewriteCond %{REQUEST_STATUS} ^400RewriteRule ^ - [E=LOG_400_ERRORS]# Define a custom log format that includes the error statusLogFormat "%h %l %u %t \"%r\" %>s \"%{Referer}i\" \"%{User-Agent}i\"" combined_with_status# Use conditional logging based on the environment variableCustomLog /tmp/400errors.log combined_with_status env=LOG_400_ERRORS
RewriteEngine On
# Redirect 400 series errors to a custom error log
RewriteCond %{REQUEST_STATUS} ^400
RewriteRule ^ - [E=LOG_400_ERRORS]
1条答案
按热度按时间fruv7luv1#
将
/tmp/400errors.log
更改为要记录输出的位置方法1 - SetEnvIf
在apache中使用
SetEnvIf
将此添加到
httpd.conf
方法2 - Mod Rewrite
在apache中使用
mod_rewrite
,无论是在你的站点配置,还是htaccess文件中