gpt4 book ai didi

curl - 如何配置Nginx充当代理的负载平衡器?

转载 作者:行者123 更新时间:2023-12-04 04:20:56 26 4
gpt4 key购买 nike

我知道可以将nginx配置为充当负载平衡器,但是我想知道是否可以在代理之间进行负载平衡?假设我在本地主机上运行多个代理,并且我想使用nginx提供一个连接点,以便我可以在这些代理之间轮换。我正在尝试实现类似于here的内容,后者使用HAProxy而不是nginx。我有以下nginx.conf:

events {  }

http {
upstream proxies {
server localhost:9998;
server localhost:9999;
server localhost:10000;
}
server {
listen 8080;

location / {
proxy_pass http://proxies;
}
}
}

但是,当我发送像这样的curl请求时:
curl http://icanhazip.com -x localhost:8080

它忽略了url,并且得到的响应类似于如果我直接向其中一个代理服务器发送请求时所期望的响应:
curl localhost:9999

当然,我并不真正希望它能起作用,因为必须有某种选择来告诉nginx将上游服务器本身当作代理。但是,在线搜索后,我找不到如何执行此操作的方法。

最佳答案

正如您在haproxy帖子中看到的haproxy akt作为转发代理

option http_proxy



手动 https://cbonte.github.io/haproxy-dconv/1.6/configuration.html#4-option%20http_proxy中描述了此选项的含义

It sometimes happens that people need a pure HTTP proxy which understands basic proxy requests without caching nor any fancy feature. In this case, it may be worth setting up an HAProxy instance with the "option http_proxy" set. In this mode, no server is declared, and the connection is forwarded to the IP address and port found in the URL after the "http://" scheme.

No host address resolution is performed, so this only works when pure IP addresses are passed. Since this option's usage perimeter is rather limited, it will probably be used only by experts who know they need exactly it. This is incompatible with the HTTP tunnel mode.



据我所知,nginx没有此功能。

这是一个类似的问题。
https://superuser.com/questions/604352/nginx-as-forward-proxy-for-https

您为什么不能按照链接文章中的描述使用haproxy?

关于curl - 如何配置Nginx充当代理的负载平衡器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39093861/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com