我需要修改Apache中的LogFormat,以便添加X-Forwarded-For标头并logging客户端的真实IP。 我试图编辑在httpd.conf文件,但我然后发现LogFormat两个单独的部分。 所以我不确定它们是否是重复的,是否应该删除它们中的任何一个,我不知道要编辑哪一个,或者我应该编辑它们。 我需要一些build议。
这是第一部分:
<IfModule log_config_module> LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %b" common CustomLog "logs/access_log" common <IfModule logio_module> LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio </IfModule> </IfModule>
第二部分:
<IfModule mod_log_config.c> 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 CustomLog logs/access_log common </IfModule>
我不知道第一和第二部分有什么区别。 我可以看到两个部分是重复的两行。 那么,我应该编辑哪个部分? 从一个部分删除重复的行并保留另一个是否安全? 我可以在一个部分组合非重复的行吗? 谢谢。
根据Apache文档,这两个部分是相同的:
Description: Logging of the requests made to the server Status: Base Module Identifier: log_config_module Source File: mod_log_config.c
删除(或注释掉)你不会觉得你会使用的,否则如果由于某种原因你会改变他们的顺序(因此优先),你会有各种各样的麻烦。
IfModule指令只有在模块被加载的情况下才能进行configuration,您可以使用httpd -M -fconfiguration文件检查哪些模块,例如:
[root@apachesrv bin]# httpd -M -f conf/httpd-vserver.conf Loaded Modules: core_module (static) mpm_prefork_module (static) http_module (static) so_module (static) log_config_module (shared) authz_host_module (shared) setenvif_module (shared) mime_module (shared) dir_module (shared) alias_module (shared) cache_module (shared) disk_cache_module (shared) headers_module (shared) deflate_module (shared) rewrite_module (shared) proxy_module (shared) proxy_http_module (shared) schema_module (shared) Syntax OK
在这种情况下,你可以看到我正在使用log_config_module,所以它会采取(在我的情况下)的configuration
<IfModule log_config_module> LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %b" common CustomLog "logs/access_log" common <IfModule logio_module> LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio </IfModule> </IfModule>
为了捕捉你需要的信息,你需要configuration一个类似如下的日志:
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{X-Forwarded-For}i\"" combinedcustomized
然后将您的访问日志更改为:
CustomLog logs/access.log combinedcustomized
编辑:
在Apache文档,你有可用的参数列表来logginghttp://httpd.apache.org/docs/2.4/mod/mod_log_config.html