V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
xoxo419
V2EX  ›  问与答

docker 如何让 Nginx 获取到访问者 IP?

  •  
  •   xoxo419 · 2018-09-13 16:05:19 +08:00 · 6340 次点击
    这是一个创建于 2052 天前的主题,其中的信息可能已经有所发展或是发生改变。

    现在有没有简单的方式通过配置下就可以的方法呢?

    通过 Google 查到的相关问题

    Document how to get real remote client ip for service running in container

    nginx 获取客户端 IP 实现 根据配置了但无法获取到真实 IP

    network_mode-docker 网络连接方式

    nginx cannot get to client IP

    第 1 条附言  ·  2018-09-15 15:15:25 +08:00
    MAC- 只能获取容器的 IP. 但是 Linux 上可以获取到客户端的真实 IP [关于问题相关的资料]( http://www.majianwei.com/archives/7909)
    8 条回复    2020-03-04 17:50:30 +08:00
    precisi0nux
        1
    precisi0nux  
       2018-09-13 16:19:52 +08:00 via iPhone
    X-Forwarded-For
    xoxo419
        2
    xoxo419  
    OP
       2018-09-13 19:08:20 +08:00
    @precisi0nux 直接 nginx 配置? 我有测试过, 不行呢.
    sky101001
        3
    sky101001  
       2018-09-13 22:35:41 +08:00 via iPad
    同 X-Forwarded-For,可以正确获取真实 ip
    xoxo419
        4
    xoxo419  
    OP
       2018-09-13 22:39:18 +08:00
    @sky101001 只是改 Nginx 配置就行么 还需要做其他的配置?

    https://github.com/docker/for-mac/issues/180
    autotesting
        5
    autotesting  
       2019-04-15 18:08:49 +08:00
    @xoxo419 取到真实 ip 现在好像还是不行呢,你当时怎么解决的呀?
    xoxo419
        6
    xoxo419  
    OP
       2019-04-16 10:37:16 +08:00
    @autotesting 服务器放在外网的就可以、
    autotesting
        7
    autotesting  
       2019-04-16 10:47:22 +08:00
    @xoxo419 啥意思,啥叫服务器放在外网,是 docker 部署在 linux 上的意思吗?
    hzw1199
        8
    hzw1199  
       2020-03-04 17:50:30 +08:00
    Nginx 如果部署成一个容器,而且网络不是 host 模式,至少现在来看是不可能获取到真实 ip 的。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3812 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 10:19 · PVG 18:19 · LAX 03:19 · JFK 06:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.