您的位置:首页 > 运维架构 > 反向代理

Varnish 反向代理,让后端服务器日志记录真实来源IP

2012-11-08 10:20 357 查看
Apache :

LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" varnishcombined

ServerName www.example.com

# [...]

CustomLog /var/log/apache2/www.example.com/access.log varnishcombined

# [...]

这样在apache的日志文件中就可以看到客户端真实的IP地址了。如果无法显示,则需要修改Varnish的配置文件

sub vcl_recv {

# Add a unique header containing the client address

remove req.http.X-Forwarded-For;

set req.http.X-Forwarded-For = client.ip;

# [...]

}

我这里测试的情况是如果我添加上面的两行,apache的日志就会输出两个客户端的ip地址。因此我没添加这两行。

Nginx:

log_format access '$remote_addr - $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" $http_x_forwarded_for';

access_log /usr/local/nginx/logs/access.log access;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: