Haproxy 讓後端RS記錄真實IP

1、修改haproxy.cfg配置文件,在defaults中加入以下兩行,並重啓haproxy。nginx

vim /etc/haproxy/haproxy.cfg
defaults
    option http-server-close
    option forwardfor

/etc/init.d/haproxy restart

2、修改nginx日誌文件格式,並重啓nginx。vim

注:nginx編譯的時候須要有--with-http_realip_module此參數spa

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

3、請求日誌格式rest

{"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"
相關文章
相關標籤/搜索