# Multiple proxy\_pass destinations from a single location block

**URL:** <https://www.ruby-forum.com/t/multiple-proxy-pass-destinations-from-a-single-location-block/234071>\
**Category:** NGINX\
**Created:** [February 4, 2015, 10:11am UTC](https://www.ruby-forum.com/t/multiple-proxy-pass-destinations-from-a-single-location-block/234071 "2015-02-04T10:11:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [February 4, 2015, 10:11am UTC](https://www.ruby-forum.com/t/multiple-proxy-pass-destinations-from-a-single-location-block/234071/1 "2015-02-04T10:11:40Z")

</div>

Is it possible to specify multiple proxy\_pass destinations from a single  
location block? Currently we have:

location ~ ^/v1/?(?.+)? {  
resolver 208.67.222.222 208.67.220.220 valid=300s;  
resolver\_timeout 10s;  
proxy\_intercept\_errors off;  
proxy\_hide\_header Vary;  
proxy\_set\_header Host “[foo.mydomain.io](http://foo.mydomain.io)”;  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
proxy\_pass [https://foo.mydomain.io/api/$url](https://foo.mydomain.io/api/$url);  
proxy\_connect\_timeout 10s;  
proxy\_read\_timeout 60s;  
proxy\_ssl\_session\_reuse on;  
proxy\_ssl\_trusted\_certificate /etc/pki/tls/certs/ca-bundle.crt;  
proxy\_ssl\_verify on;  
proxy\_ssl\_verify\_depth 2;  
proxy\_ssl\_ciphers “EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM  
EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384  
EECDH+aRSA+SHA256  
EECDH+aRSA+RC4 EECDH EDH+aRSA RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP  
!PSK  
!SRP !DSS”;  
}

I’d like to keep all the above logic, but ALSO set up another proxy\_pass  
from this location block to say [bar.mydomain.com](http://bar.mydomain.com). What is the best way  
to do  
this?

Posted at Nginx Forum:

> **[Multiple proxy\_pass destinations from a single location block](https://forum.nginx.org/read.php?2,256437,256437#msg-256437)**
>
> Is it possible to specify multiple proxy\_pass destinations from a single location block? Currently we have: location ~ ^/v1/?(?\<url\>.+)? { resolver 208.67.222.222 208.67.220.220 valid=300s; resolver\_timeout 10s; proxy\_intercept\_errors off;

---

<div class="post-metadata">

**Author:** ![justink101](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a587f6/32.png) [@justink101](https://www.ruby-forum.com/u/justink101)\
**Post date:** [February 4, 2015, 10:18am UTC](https://www.ruby-forum.com/t/multiple-proxy-pass-destinations-from-a-single-location-block/234071/2 "2015-02-04T10:18:04Z")

</div>

On 04 Feb 2015, at 12:11, justink101 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
> !SRP !DSS";  
> }
> 
> I’d like to keep all the above logic, but ALSO set up another proxy\_pass  
> from this location block to say [bar.mydomain.com](http://bar.mydomain.com). What is the best way to do  
> this?

The first thing you do not need regex here:

location /v1/ {  
proxy\_pass [http://foo.mydomain.io/api/](http://foo.mydomain.io/api/);  
…  
}

is enough.

To add another server to proxy\_pass you can use upstream:

upstream mydomain {  
server [foo.mydomain.io](http://foo.mydomain.io);  
server [bar.mydomain.com](http://bar.mydomain.com);  
}

server {  
…  
location /v1/ {  
proxy\_pass [http://mydomain/api/](http://mydomain/api/);  
…  
}

–  
Igor S.

> **[F5 NGINX: Built for cloud-native apps. Ready for AI traffic.](https://www.f5.com/products/nginx)**
>
> Deliver modern applications with NGINX. Explore high-performance load balancing, API gateways, and web server solutions trusted by top global enterprises.

---

<div class="post-metadata">

**Author:** ![justink101](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a587f6/32.png) [@justink101](https://www.ruby-forum.com/u/justink101)\
**Post date:** [February 5, 2015, 9:27am UTC](https://www.ruby-forum.com/t/multiple-proxy-pass-destinations-from-a-single-location-block/234071/3 "2015-02-05T09:27:02Z")

</div>

Thanks Igor.

What if one of the servers listed in the upstream block should be over  
https  
and the other over http? How is this done using

upstream proxies {  
server [foo.mydomain.io](http://foo.mydomain.io);  
server [bar.mydomain.com](http://bar.mydomain.com);  
}

proxy\_pass [https://proxies/api/](https://proxies/api/);

Notice the proxy pass defines only a single scheme (https).

Posted at Nginx Forum:

> **[Re: Multiple proxy\_pass destinations from a single location block](https://forum.nginx.org/read.php?2,256437,256461#msg-256461)**
>
> Is it possible to specify multiple proxy\_pass destinations from a single location block? Currently we have: location ~ ^/v1/?(?\<url\>.+)? { resolver 208.67.222.222 208.67.220.220 valid=300s; resolver\_timeout 10s; proxy\_intercept\_errors off;

---

<div class="post-metadata">

**Author:** ![justink101](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a587f6/32.png) [@justink101](https://www.ruby-forum.com/u/justink101)\
**Post date:** [February 5, 2015, 1:39pm UTC](https://www.ruby-forum.com/t/multiple-proxy-pass-destinations-from-a-single-location-block/234071/4 "2015-02-05T13:39:11Z")

</div>

On 05 Feb 2015, at 11:26, justink101 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> proxy\_pass [https://proxies/api/](https://proxies/api/);
> 
> Notice the proxy pass defines only a single scheme (https).

No easy way.

–  
Igor S.

> **[F5 NGINX: Built for cloud-native apps. Ready for AI traffic.](https://www.f5.com/products/nginx)**
>
> Deliver modern applications with NGINX. Explore high-performance load balancing, API gateways, and web server solutions trusted by top global enterprises.

---

<div class="post-metadata">

**Author:** ![justink101](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a587f6/32.png) [@justink101](https://www.ruby-forum.com/u/justink101)\
**Post date:** [March 13, 2015, 11:17am UTC](https://www.ruby-forum.com/t/multiple-proxy-pass-destinations-from-a-single-location-block/234071/5 "2015-03-13T11:17:52Z")

</div>

When you say " but ALSO set up another proxy\_pass from this location  
block  
to say [bar.mydomain.com](http://bar.mydomain.com)"

Do you mean the request should go to both? i.e foo.mydomian and  
bar.mydomain. If thats the case than upstream will not work because it  
will  
actually load balance the requests between 2 servers.

Infact I am also looking for a solution wherein I need proxy\_pass to  
send  
request to the destined server but ALSO send it to another server also  
(in  
async manner).

I tried using echo module with echo\_subrequest\_async but it did not  
worked.  
So I am not sure whats the best way to do that in Nginx

check this [Echo sub request not working](http://forum.nginx.org/read.php?2,257211,257211)

Posted at Nginx Forum:

> **[Re: Multiple proxy\_pass destinations from a single location block](https://forum.nginx.org/read.php?2,256437,257238#msg-257238)**
>
> Is it possible to specify multiple proxy\_pass destinations from a single location block? Currently we have: location ~ ^/v1/?(?\<url\>.+)? { resolver 208.67.222.222 208.67.220.220 valid=300s; resolver\_timeout 10s; proxy\_intercept\_errors off;
