Forum: NGINX Dynamic upstream proxy_pass

2974d09ac2541e892966b762aad84943?d=identicon&s=25 kay (Guest)
on 2014-04-09 10:19
(Received via mailing list)
I'm trying to set upstream names by variables, but nginx recognizes
variables as hostnames, not upstream names.

For example:
map $cookie_backend $proxy_host {
    default     'backend1';
    '1'             'backend2';
}
... ... ...
upstream backend1 {
    server backend123:8080;
    server backend124:8080;
}
... ... ...
upstream backend2 {
    server backend223:8080;
    server backend224:8080;
}
... ... ...
location / {
    proxy_pass      http://$proxy_host;
}

nginx returns error message:
2014/04/09 14:19:51 [error] 1085#0: *1128620 backend1 could not be
resolved
(3: Host not found) while sending to client, client: 192.168.1.145,
server:
localhost, request: "GET / HTTP/1.1", host: "localhost"

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,249142,249142#msg-249142
7c401942fa6feef9792b64ba0230156b?d=identicon&s=25 Makailol Charls (Guest)
on 2014-04-09 10:30
(Received via mailing list)
Hello!

You need to use resolver directive in Nginx.
Also you need to set DNS entries for your backend hostname.

Best regards,
Makailol
2974d09ac2541e892966b762aad84943?d=identicon&s=25 kay (Guest)
on 2014-04-09 11:04
(Received via mailing list)
My bad, in one location I forgot to remove port, that is why nginx tried
to
resolve upstream as hostname.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,249142,249145#msg-249145
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.