大网数据广告活动
服务器运维问答

How to forward client's IP address to Nginx from Haproxy in tcp mode

· 52CE 我爱测

I want to forward real client's ip address from haproxy to my backend servers in tcp mode. The configuration of Haproxy is as follows: frontend main bind *:80 mode http option forwardfor option http-server-close default_backend a…

问题原文

原帖链接 · Sinai · CC BY-SA 3.0

I want to forward real client's ip address from haproxy to my backend servers in tcp mode. The configuration of Haproxy is as follows:

frontend main
    bind *:80
    mode http
    option forwardfor
    option http-server-close    
    default_backend app-main

frontend https_main
    bind *:443
    mode tcp
    option tcplog
    option tcpka
    default_backend app-ssl

backend app-main
    balance roundrobin
    server web1 192.168.1.22:8080 check fall 3 rise 2
    server web2 192.168.1.33:8080 check fall 3 rise 2

backend app-ssl
    balance roundrobin
    mode tcp
    option ssl-hello-chk
    server web3 192.168.1.44:443

backend servers for http requests are apache and I have replaced the following line in httpd.conf with log lines, so I can now get the client's ip addreses correctly:

LogFormat "%h %l %u %t \"%r\" %>s %b %{X-Forwarded-For}i" common

My backend server for https uses Nginx as a reverse_proxy for ssl termination and sends the requests to apache backends. My problem is that I don't know how can I get the real client's ip address in nginx logs? I googled a lot and found some solution on serverfault and stackoverflow, but none of them resolved my problem in forwarding client's ip address in tcp mode in haproxy. Any help is appreciated.

已采纳解答

原帖链接 · Fedor Dikarev · CC BY-SA 3.0

You should use listen 443 ssl proxy_protocol; on nginx side and send_proxy directive on Haproxy side.

Using Proxy Protocol with Nginx

Haproxy documentation

Send PROXY protocol header from HAProxy

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-08-10)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。