使用 haproxy 作为反向代理,在 Internet 代理后面的应用程序

Use haproxy as a reverse proxy with an application behind Internet proxy

我需要在公共内部托管下集成多个本地和异地 Web 应用程序 URL。 on-premise 应用程序与 haproxy 在同一个数据中心,但异地应用程序只能通过 http 代理访问,因为 haproxy 运行ning 所在的服务器无法直接访问 Internet。因此我必须使用 http Internet 代理,SOCKS 也可能是一个选项。

如何告诉 haproxy 后端只能通过代理访问? 我宁愿 使用额外的组件,如 socksify / proxifier / proxychains / tsocks / ... 因为这会引入额外的开销。

此图显示了设置中涉及的组件:

当我 运行 在机器上 使用直接互联网连接时 我可以使用这个配置并且它工作得很好:

frontend  main
    bind *:8000
    acl is_extweb1 path_beg -i /policies
    acl is_extweb2 path_beg -i /produkte

    use_backend externalweb1 if is_extweb1
    use_backend externalweb2 if is_extweb2

backend externalweb1
    server static www.google.com:80 check

backend externalweb2
    server static www.gmx.net:80 check

(显然这些不是我正在与之交谈的 URL,这只是一个例子)

Haproxy 能够检查外部应用程序并将流量路由到它们:

在我工作的公司的安全环境中,我必须使用代理,而haproxy无法连接到外部应用程序。 我如何启用 haproxy 在通过通用 http 页面/通过浏览器提供对它们的访问的同时使用 http 代理后面的那些外部 Web 应用程序服务器(无需身份验证)?

如何为此使用委托(http://delegate.org/documents/),作为一个想法。

haproxy -> delegate -f -vv -P127.0.0.1:8081 PROXY=<your-proxy>

http://delegate9.org/delegate/Manual.shtml?PROXY

我知道它不是那么优雅,但它可以工作。

我已经用本地 squid 和这个 curl 调用测试了这个设置

echo 'GET http://www.php.net/' |curl -v telnet://127.0.0.1:8081

curl 调用模拟 haproxy tcp 调用。

我很想让它工作,但我真的在 haproxy 文档中找不到任何东西,所以我用谷歌搜索了一下,发现 nginx might do the trick, but it didn't for me, after a bit more of googleing i ended up finding a configuration for apache 可以工作。

这是重要的部分:

Listen 80

SSLProxyEngine on

ProxyPass /example/ https://www.example.com/
ProxyPassReverse /example/ https://www.example.com/
ProxyRemote https://www.example.com/ http://corporateproxy:port

ProxyPass /google/ https://www.google.com/
ProxyPassReverse /google/ https://www.google.com/
ProxyRemote https://www.google.com/ http://corporateproxy:port

我很确定应该有一种方法可以将此配置转换为 nginx 甚至转换为 haproxy...如果我设法找到时间,我会根​​据我的发现更新答案。

要使 Apache 正常工作,您还应该启用一些模块,我提供了一个 github repository 和一个基本的 docker 配置,可以随意展示查看完整的工作配置。