apache - 在 Apache2 访问日志中记录 HTTP header

标签 apache logging http-headers

我有一个在 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/

相关文章:

php - Laravel 5 如何全局设置 Cache-Control HTTP header ?

django - 如何使用 wsgi_mod 在 ubuntu 中托管 django 项目

node.js - 有没有办法在 Node 服务器的 httpd conf 中设置 ProxyPass

php - ZeroMQ Apache 模块

python - 为什么无法在 Windows 上清除临时目录中我的文件处理程序的文件?

spring-mvc - Spring MVC @RequestMapping header 只能接受一个值吗?

windows - 如何让 Windows Apache 使用所有 cpu 内核?

postgresql - 使用 docker-compose 在 postgresql 中启用日志记录

c# - 用于登录 .NET 的堆栈跟踪

ios6 - IOS HTTP 请求示例