【问题标题】:How to redirect request from nginx reverse proxy back to localhost如何将来自 nginx 反向代理的请求重定向回 l​​ocalhost
【发布时间】:2018-12-19 11:21:39
【问题描述】:

我是 nginx 和 docker-compose 的新手。 我有一个 docker-compose,其中包含一个 nginx-reverse-proxy 和许多称为 webapi01、webapi02 的 Web API ...

在 nginx-reverse-proxy 中,我有

  location /app1/{
        proxy_pass http://webapi01:5000/;
    }
    location /app2/{
        proxy_pass http://webapi02:5000/;
    }

他们工作正常。

现在启动我的 docker-compose 后,我想通过修改指向我的 webApi01 的位置来调试我的 webapi01,并期望该请求将命中在 http://localhost:5000 列出的调试实例 webapi01

 location /app1/{
     #proxy_pass http://webapi01:5000/;
     # what should be here so the request will be forward to the localhost(the machine, not the docker-compose ) so I can debug my webapi01
     proxy_pass http://127.0.0.1:5000/;
 }

但是,我无法让它工作。日志显示错误:connect() failed (111: Connection refused) while connection to upstream .......

那么问题是如何将请求从 nginx-reverse-proxy 重定向回主机(localhost)?

任何帮助或建议将不胜感激。

谢谢,

奥斯汀

【问题讨论】:

    标签: docker-compose nginx-reverse-proxy


    【解决方案1】:

    我找到了解决方案。 https://medium.com/@bsamartins/reverse-proxy-nginx-docker-container-to-localhost-7ebc53577192

    location /app1/{
         # this line will connect to your running instance in docker-compose
         #proxy_pass http://webapi01:5000/;
         # this line will forward to the localhost(the machine, not the docker-compose ) so I can debug my webapi01
         proxy_pass http://docker.for.win.localhost:5000/;
     }
    

    【讨论】:

      猜你喜欢
      • 2018-02-22
      • 2018-06-20
      • 2014-10-24
      • 2019-03-12
      • 2015-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多