我知道nginx可以被配置为充当负载均衡器,但我想知道是否可以在代理之间进行负载均衡?假设我有多个代理在本地主机上运行,并且我想使用nginx提供单一连接点,以便我可以在代理之间轮换。我试图实现类似于这里的帖子所描述的内容,该帖子使用的是HAProxy而不是nginx。我有以下
然而,当我发送类似这样的curl请求时:
它忽略了URL,我收到的响应类似于如果我直接向其中一个代理服务器发送请求时所期望的响应:
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将upstream服务器本身视为代理。然而,在网上搜索后我没有找到如何做到这一点。
proxy_set_header Host $host;
。 - regilero