我已经把varnish设置为代理,将HTTP请求redirect到运行apache的后端服务器。 我希望在我的Apache日志,而不是清漆服务器IP地址的客户端IP地址。 这是我的清漆configuration文件:
backend $my_backend { .host = "192.168.0.103"; .port = "80"; } sub vcl_recv { } else if (req.http.host == "$my_domain_name") { set req.backend = $my_backend; if (req.request == "POST") { if (req.http.X-Forwarded-For) { set req.http.X-Real-Forwarded-For = req.http.X-Forwarded-For ", " regsub(client.ip, ":.*", ""); unset req.http.X-Forwarded-For; } else { # Simply use the client IP set req.http.X-Real-Forwarded-For = regsub(client.ip, ":.*", ""); } return(pipe); } return(lookup); } }
在后端的Apacheconfiguration文件,我有这个
RPAFenable On RPAFsethostname On RPAFproxy_ips $varnish_proxy_ip RPAFheader X-Real-IP
问题是在Debian6上不能识别指令RPAFheader:
root@$hostname:~# apache2ctl configtest Invalid command 'RPAFheader', perhaps misspelled or defined by a module not included in the server configuration Action 'configtest' failed. The Apache error log may have more information. root@$hostname:~#
有没有人在Debian上设置mod_rpaf来帮我解决这个问题mod_rpaf
非常感谢您的帮助!
好吧,我会回答我自己的问题,以帮助可能有同样问题的人:
首先将下列行添加到清漆configuration文件(default.vcl)
sub vcl_recv { if (req.http.host == "myDomain.net") { set req.http.host = "myDomain.net"; set req.backend = myBackend; # Compatiblity with Apache log remove req.http.X-Forwarded-For; set req.http.X-Forwarded-For = client.ip; # No cache for POST requests if (req.request == "POST") { return(pipe); } return(lookup); } }
然后在configuration虚拟主机的同时为apache添加个性化的日志格式
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" varnishcombined ... CustomLog ${APACHE_LOG_DIR}/access.log varnishcombined
而已!