Multiple proxy_pass destinations from a single location block
Igor Sysoev
igor at sysoev.ru
Wed Feb 4 09:17:33 UTC 2015
On 04 Feb 2015, at 12:11, justink101 <nginx-forum at nginx.us> wrote:
> 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;
> 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?
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 Sysoev
http://nginx.com
More information about the nginx
mailing list