我有一个在 Cloudflare 后面运行的网站,它是一个反向代理。这意味着我在访问日志中只会得到一两个 IP 地址。
但是,Cloudflare 确实在请求 header 中提供了访问者 IP 地址,我假设我可以在访问日志中记录而不是标准地址。
我知道如何使用 CustomLog
,但是有没有办法在 Apache 访问日志中保存 HTTP header ?
谢谢。
最佳答案
是的 - 看看文档 - http://httpd.apache.org/docs/2.2/mod/mod_log_config.html特别是条目
%{Foobar}i
这将使您:
The contents of Foobar: header line(s) in the request sent to the server. Changes made by other modules (e.g. mod_headers) affect this. If you're interested in what the request header was prior to when most modules would have modified it, use mod_setenvif to copy the header into an internal environment variable and log that value with the %{VARNAME}e described above.
所以人们通常会在 CustomLog 条目中添加一些像“... %{X-Forwarded-For-IP}i”这样的条目。
将“X-Forwarded-For-IP”替换为您的 cloudflare 服务为您提供的任何内容(通常类似于 ''"CF-Connecting-IP"'');例如
LogFormat "%v %{CF-Connecting-IP}i (via cloudflare:%h) %l %u %t \"%r\" %>s %b" cloudflare
CustomLog "|rotatelog.. etc" cloudflare
关于“传输日志”——请参阅 TransferLog 指令附近的注释——它选择最新定义的版本。
体重。
关于apache - 在 Apache2 访问日志中记录 HTTP header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12248549/