1.nginx http 七层代理
修改命令空间:
namespace: nginx-ingress :
configmap:nginx-configuration
kubectl get cm nginx-configuration -n ingress-nginx -o yaml
添加如上配置
compute-full-forwarded-for: “true”
forwarded-for-header: X-Forwarded-For
use-forwarded-headers: “true”
即可;
2. nginx stream 4层代理:
nginx 需要编译增加–with-stream_realip_module模块,然后对应的server块中添加参数,proxy_protocol on; 如下图所示:
前面的4层代理更改好之后,ingress解析不了包,会报错 ‘400 Bad Request’,需要修改ingress cm nginx-configuration 配置 , 增加 use-proxy-protocol: “true” 。如下图:
查看日志,为真实客户端ip地址: