nginx单个位置到多个上游

时间:2017-07-10 08:22:19

标签: nginx location

我需要将单个位置代理到两个上游。定义了两个上游:

upstream django {
   server unix:///home/copilot/django.sock;
}
upstream trip_storage {
   server 127.0.0.1:10500;
}

通常所有内容都通过以下位置代理到Django:

location / {
   uwsgi_pass         django;

   uwsgi_param   Host                 $host;
   uwsgi_param   X-Real-IP            $remote_addr;
   uwsgi_param   X-Forwarded-For      $proxy_add_x_forwarded_for;
   uwsgi_param   X-Forwarded-Proto    $http_x_forwarded_proto;

   include uwsgi_params;
}

现在我必须代理请求/ api / trip到名为trip_storage的新后端的请求,但是为了进行测试和比较,它也应该路由到Django中的旧后端。我试图通过创建两个新位置来实现它:

location /api/trip/ {
   uwsgi_pass         triglavtest_copilot;

   uwsgi_param   Host                 $host;
   uwsgi_param   X-Real-IP            $remote_addr;
   uwsgi_param   X-Forwarded-For      $proxy_add_x_forwarded_for;
   uwsgi_param   X-Forwarded-Proto    $http_x_forwarded_proto;

   include uwsgi_params;
   # Send to trip storage
   proxy_set_header X-Forwarded-For $remote_addr;
   proxy_set_header Host $http_host;
   proxy_redirect off;
   proxy_pass http://trip_storage/api/trip_storage/smartphone/;
}

但是这种配置不起作用,而是仅代理定义的proxy_pass,忽略uwsgi_pass。是否有其他方法将单个位置代理到多个上游?

0 个答案:

没有答案