jcmoraisjr / haproxy-ingress

HAProxy Ingress
https://haproxy-ingress.github.io
Apache License 2.0
1.04k stars 269 forks source link

how can get real ip of client by haproxy in kubernets #153

Open ansongit opened 6 years ago

ansongit commented 6 years ago

my haproxy config like below: global log 127.0.0.1 local0 info daemon user haproxy group haproxy maxconn 64000

defaults log global stats uri /haproxy-stats timeout connect 30000ms option dontlognull option http-server-close maxconn 64000 timeout client 900000ms timeout server 900000ms

frontend http_front bind *:80 mode http stats uri /haproxy?stats option httplog option http-server-close option forwardfor reqadd X-Forwarded-Proto:\ http default_backend http_back

capture cookie last-sid len 63
capture request header Host len 64 capture request header User-Agent len 128 capture request header X-Forwarded-For len 100 capture request header Referer len 200 capture response header Server len 40 capture response header Server-ID len 40 log-format %ci:%cp\ %si:%sp\ %B\ %U\ %ST\ %f\ %b\ %bi\ %r\ %CC\ %CS\ %hrl\ %hsl\ backend http_back mode http balance roundrobin option forwardfor option http-server-close server gorouter gorouter.default:80 check

but the final log like that: May 8 07:46:19 localhost haproxy[26]: 172.17.91.0:51752 10.254.175.219:80 2337 492 200 http_front http_back 172.17.58.5 GET /resources/messages/zh_CN.yaml HTTP/1.1 - last-sid=f568fbc2-4eda-446b-a935-2dfc7900f28c api.dop-v2.nieo.top:585 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36 - http://api.dop-v2.nieo.top:585/login Apache-Coyote/1.1 -\

i want get the real ip, which comes from outside. but i just get the ip 172.17.91.0:51752, which is a inner container ip. is something wrong in my haproxy.conf?

jcmoraisjr commented 6 years ago

This happens when you use a proxy/nat in front of HAProxy, eg k8s node port or k8s services. There is some info about this on #6 . Missing to write somewhere in the docs.