Multiple proxy_pass destinations from a single location block

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”;
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;
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. What is the best way
to do
this?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,256437,256437#msg-256437

On 04 Feb 2015, at 12:11, justink101 [email protected] 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. 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/;

}

is enough.

To add another server to proxy_pass you can use upstream:

upstream mydomain {
server foo.mydomain.io;
server bar.mydomain.com;
}

server {

location /v1/ {
proxy_pass http://mydomain/api/;

}


Igor S.
http://nginx.com

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;
server bar.mydomain.com;
}

proxy_pass https://proxies/api/;

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

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,256437,256461#msg-256461

On 05 Feb 2015, at 11:26, justink101 [email protected] wrote:

proxy_pass https://proxies/api/;

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

No easy way.


Igor S.
http://nginx.com

When you say " but ALSO set up another proxy_pass from this location
block
to say 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 http://forum.nginx.org/read.php?2,257211,257211

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,256437,257238#msg-257238

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs