一、修改haproxy.cfg配置文件,在defaults中加入如下两行,并重启haproxy。
vim /etc/haproxy/haproxy.cfg defaults option http-server-close option forwardfor
/etc/init.d/haproxy restart
二、修改nginx日志文件格式,并重启nginx。
注:nginx编译的时候需要有--with-http_realip_module此参数
vim /etc/nginx/nginx.conf log_format main '{"Request_time":"$time_local",' '"Request_Real_Client":"$remote_addr",' '"Request_Mothod":"$request",' '"Forward_Real_WebServer_Status_Code":"$status",' '"Request_Size":"$body_bytes_sent",' '"Request_Http_Referer":"$http_referer"}' '"Request_User_Agent":"$http_user_agent",' '"Forward_Real_WebServer":"$http_x_forwarded_for"';
nginx -s reload
三、请求日志格式
{"Request_time":"12/Jun/2019:14:52:47 +0800","Request_Real_Client":"192.168.7.80","Request_Mothod":"GET / HTTP/1.1","Forward_Real_WebServer_Status_Code":"304",
"Request_Size":"0","Request_Http_Referer":"-"}"Request_User_Agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/74.0.3729.169 Safari/537.36","Forward_Real_WebServer":"192.168.1.50"