运行8080上的Apache和80上的Varnish的Ubuntu 9.04盒子。
最近成立了Munin,并想知道为什么Apache图表是空的。 从Munin正在访问/server-status?auto的日志中看到,并得到403 Forbidden 。 所以我编辑/etc/apache2/monds-enabled/status.conf以允许从127.0.0.1访问。 但是这样做实际上是公开的/server-status ,因为来自Varnish的请求也来自127.0.0.1 。
所以问题是,如何configurationmod_status只能由munin-node访问,而不能通过Varnish?
我解决这个问题的方法是通过确保Apache获取实际访问者的IP,即使请求经过varnishcaching。 我使用的是Apache mod_rpaf(请参阅http://giantdorks.org/alain/easily-get-the-correct-client-ip-with-mod_rpaf/ )。
此外,为了防止客户端的请求也通过一些设置X-Forwarded-For头的代理,我将其重置在我的varnishcaching实例(在vcl_recv中):
remove req.http.X-Forwarded-For; set req.http.X-Forwarded-For = client.ip;
然后也告诉varnish永远caching/ server-status和/ server-info的响应。 以下(也在vcl_recv中)适用于我:
if (req.url ~ "server-(info|status)") { return (pass); }
这看起来像一个解决scheme,告诉我你的想法。
Varnish为每个向后端发送的请求添加一些HTTP头像X-Varnish 。 这些可以在Apacheconfiguration中用来识别来自Varnish的请求。
在/etc/apache2/mods-enabled/status.conf :
<IfModule mod_status.c> SetEnvIf X-Varnish ".+" from_varnish ExtendedStatus On <Location /server-status> SetHandler server-status Order allow,deny Deny from env=from_varnish Allow from localhost ip6-localhost 127.0.0.1 </Location> </IfModule>
然后告诉munin监视端口8080而不是80.来自munin-node请求将直接发送,因此不会有X-Varnish头文件集。
添加到/etc/munin/plugin-conf.d/munin-node :
[apache_*] env.url http://127.0.0.1:%d/server-status?auto env.ports 8080
我和Ubuntu 12.04,端口8008上的Apache2以及端口80上的Varnish具有相同的情况。使用Varnish VCL时,我使用我的服务器状态页面被caching了一个小时,所以它仍然可用,但只有在caching时才提供状态报告刷新。 通过实施Alain的解决scheme,通过Varnish将活服务器状态传递给后端。 为了确保我的服务器状态,我做了以下操作:
我在/etc/munin/plugin-conf.d/munin-node中configuration了munin-node来监听8008:
[apache_*] env.url http://127.0.0.1:%d/server-status?auto env.ports 8008
然后,我在vcl_recv部分的顶部添加了以下行到我的VCL:
if (req.url ~ "^/server-status") { error 403; }
这阻止了对端口80上的服务器状态URL的访问,但有一个403禁止消息,但是munin-node仍然可以连接到localhost上的服务器状态:8008
这篇文章是有帮助的: http : //nwlinux.com/how-to-configure-varnish-on-ubuntu-server/