四、Haproxy的4层及7层IP透传
四层IP透传配置
haproxy 配置: listen web_prot bind 192.168.32.204:80 mode tcp balance roundrobin server web1 10.0.0.201 send-proxy check inter 3000 fall 3 rise 5 nginx配置: server { listen 80 proxy_protocol; #listen 80; server_name 10.0.0.201; ......
haproxy 配置: defaults option forwardfor 或者: option forwardfor header X-Forwarded-xxx #自定义传递IP参数,后端web服务器写X-Forwarded-xxx,如 果写option forwardfor则后端服务器web格式为X-Forwarded-For listen配置: listen web_host bind 192.168.32.204:80 mode http log global balance random server web1 10.0.0.201:80 weight 1 check inter 3000 fall 2 rise 5 server web2 10.0.0.202:80 weight 1 check inter 3000 fall 2 rise 5
web服务器日志格式配置
#apache 配置: LogFormat "%{X-Forwarded-For}i %a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User- Agent}i\"" combined #tomcat 配置: pattern='%{X-Forwarded-For}i %l %T %t "%r" %s %b "%{User-Agent}i"'/> #nginx 日志格式: log_format main '"$http_x_forwarded_For" - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" ';
I have a dream so I study hard!!!