bboysoulcn
V2EX  ›  问与答

traefik 后端的应用怎么获取访问的真实 ip?

  •  
  •   bboysoulcn · Mar 6, 2020 · 3495 views
    This topic created in 2282 days ago, the information mentioned may be changed or developed.
    4 replies    2020-03-07 10:22:17 +08:00
    NauxLiu
        1
    NauxLiu  
       Mar 6, 2020
    通过 X-Forard-For header。
    NauxLiu
        2
    NauxLiu  
       Mar 6, 2020
    哎呀,手误打错了, 是 `X-Forwarded-For`
    hzfyjgw
        3
    hzfyjgw  
       Mar 6, 2020 via Android
    给 service 的 spec 加上 externalTrafficPolicy=Local
    bboysoulcn
        4
    bboysoulcn  
    OP
       Mar 7, 2020
    已解决
    我的是 swarm 集群
    command 上加上
    - --entryPoints.web.address=:80
    - --entryPoints.web.forwardedHeaders.trustedIPs=0.0.0.0/0
    这样 X-Forwarded-For 上就有真实 ip 了
    但是头部会有两个 ip
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2815 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 01:23 · PVG 09:23 · LAX 18:23 · JFK 21:23
    ♥ Do have faith in what you're doing.