基于remote_addr的Nginx上行

你有什么想法,是否有任何更容易的解决scheme来传递请求到不同的上游基于访客的IP地址?

我目前唯一find的解决scheme是:

upstream live { ip_hash; server 10.0.0.1; } upstream test { ip_hash; server 10.0.0.2; } location / { if ($remote_addr = "10.0.0.101") { proxy_pass http://test; } proxy_pass http://live; // the rest of the bla bla } 

这解决了这个问题,如果你只是“位置”,只有一个IP地址,应该去“testing”上游。 包含configuration文件(不工作)时,我尝试了if语句。 我也试图把当上游声明的时候(相同,不工作)。

所以,如果有人正在做类似的事情,将不胜感激(我敢肯定,我不是唯一有这个问题的人)。 我需要这个解决scheme让我们的开发人员testing真正的环境…这是因为我们使用的支付解决scheme允许我们只从当前的基础设施发送请求。

谢谢。

尝试这个:

  geo $upstream_addr { 10.0.0.101/32 test; default live; } ... location / { proxy_pass http://$upstream_addr; ... }