ioioioioioioi
V2EX  ›  问与答

Nginx 反代如何传递 IP?

  •  
  •   ioioioioioioi · Jan 18, 2017 · 2135 views
    This topic created in 3427 days ago, the information mentioned may be changed or developed.
    入口服务器 A 配置:
    proxy_set_header X-Real-IP $remote_addr;

    下一个服务器 B 配置:
    proxy_set_header X-Real-IP $http_x_real_ip;


    但是服务器 B 的 X-Real-IP 并非用户 IP ,而是服务器 A 的 IP
    8 replies    2017-01-19 08:10:33 +08:00
    shyling
        1
    shyling  
       Jan 18, 2017   ❤️ 1
    用 X-Forwarded-For: client1, proxy1, proxy2, proxy3
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    lhbc
        2
    lhbc  
       Jan 18, 2017
    服务器 B:
    http {
    set_real_ip_from <服务器 A 的 IP>;
    real_ip_header X-Real-IP;
    }
    clino
        3
    clino  
       Jan 18, 2017 via Android
    X-Forwarded-For 应该是标准
    https://github.com/zhangchunlin/shapps/tree/master/shapps/auth/xforwardedfor 这个是我写的 uliweb 中间件,取 X-Forwarded-For 更新到客户端 ip 变量
    ioioioioioioi
        4
    ioioioioioioi  
    OP
       Jan 18, 2017
    @lhbc 谢谢,但是试了,不行。
    lhbc
        5
    lhbc  
       Jan 18, 2017
    @ioioioioioioi 服务器 A 还要配置
    proxy_set_header X-Real-IP $remote_addr;
    ioioioioioioi
        6
    ioioioioioioi  
    OP
       Jan 18, 2017
    @lhbc 不行,设置后,第三个服务器的 HTTP_X_REAL_IP 还是第一个服务器的 IP
    lhbc
        7
    lhbc  
       Jan 19, 2017 via iPhone
    @ioioioioioioi 服务器 B 要关掉这个
    proxy_set_header X-Real-IP $remote_addr;
    ioioioioioioi
        8
    ioioioioioioi  
    OP
       Jan 19, 2017
    @lhbc 不行,哎,放弃了,用 HTTP_X_FORWARDED_FOR 了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3668 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 00:49 · PVG 08:49 · LAX 17:49 · JFK 20:49
    ♥ Do have faith in what you're doing.