问题描述
有关我的生活,我不能让mod_remoteip得到客户IP地址在我的Apache访问日志。我工作在一个设定的Virtualmin清漆4在安装的Apache 2.4.7的面前。你如何得到它的工作?
For the life of me, I couldn't get mod_remoteip to get client IPs in my Apache access logs. I'm working on a Virtualmin setup with Varnish 4 installed in front of Apache 2.4.7. How do you get it working?
推荐答案
我终于在日志中的客户端的IP地址,我发现最后一步的位置:
I finally got the client IPs in the log and I found the last step here:
下面是步骤,以得到它的工作:
Here are the steps to getting it to work:
-
获取清漆一个头传递给Apache,与客户端IP。您可以通过包括code的此位(在此发现的answer)在你vcl_recv的开始:
Get Varnish to pass a header to Apache with the client IP. You do this by including this bit of code (found in this answer) at the very beginning of your vcl_recv:
if (req.restarts == 0) {
if (req.http.X-Forwarded-For) {
set req.http.X-Forwarded-For = req.http.X-Forwarded-For + ", " + client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
}
现在让mod_remoteip在Apache中。
Now enable mod_remoteip in Apache.
编辑Apache配置告诉mod_remoteip什么头包含客户端IP(从)。我使用的X转发,因为,但我想这可能是任何东西,只要它符合你已经配置光油传递下去:
Edit your Apache config to tell mod_remoteip what header contains the client IP (from Apache docs). I'm using X-Forwarded-For, but I suppose this could be anything as long as it matches what you've configured Varnish to pass along:
RemoteIPHeader的X转发,对于
如果你重新启动Apache和光油现在,我敢打赌,现在的Apache将引用客户端IP,而不是127.0.0.1的无处不在。除了在访问日志这是我一直在检查。要获得访问日志显示客户端IP,我们需要修改它的使用日志格式的Apache。于我而言,这是组合拳的格式。这是我的突破,我发现它here可链接到这个优秀的的信息为我们的宗旨。
If you restarted Apache and Varnish right now, I bet Apache will now reference the client IP instead of 127.0.0.1 everywhere. Except in the access logs which is where I've been checking. To get the access logs to show the client IP, we need to modify the log format Apache it's using. In my case, this was the "combined" format. This was my breakthrough and I found it here which links to this excellent information for our purposes.
这是我的组合日志格式看起来像:
This is what my combined log format looked like:
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
而我只是取代在%h后,这是什么样子%A:
And I just substituted %a in where %h was and this is what it looks like:
LogFormat "%a %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
最后,这里是我的Apache的配置文件块(前负荷mod_remoteip它)是这样的:
And finally, here's what a block of my Apache config file looks like (mod_remoteip loading prior to it):
# Note that the use of %{X-Forwarded-For}i instead of %h is not recommended.
# Use mod_remoteip instead.
RemoteIPHeader X-Forwarded-For
LogFormat "%a %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
这篇关于获得2.4的Apache访问日志显示客户端IP,而不是用光油mod_remoteip 127.0.0.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!