Score:1

Is there a way to force nginx to treat variable as upstream name, not URL?

sn flag
a p

I have a number of upstreams that I select from based on a set of headers, but am finding after the addition of https://github.com/GUI/nginx-upstream-dynamic-servers that my $destination variable is being interpreted as a URL and not an upstream. Here's a snippet:

http {
    upstream LegacyService {
        server my.server.location.com:443 max_fails=0 resolve;
    }


    upstream NewService {
        server myNew.server.location.com:443 weight=100 max_fails=0 resolve;

    }

    ... 
    map $http_some_header $destination {
        default LegacyService;
        "~marker" NewService;
    }
    
    server {
        listen localhost:8080;
        
        # lots of the usual setup
        
        location / {
            proxy_pass https://$destination;
        }
    }
}

This configuration gets me a bunch of errors as now my destinations are interpreted as URLs instead of the names of upstreams:

2021/08/09 11:05:56 [error] 15326#0: *5761 no live upstreams while connecting to upstream, client: 10.1.1.5, RequestID: 6ef3b58fc95e07b083e6186df62ba15d, server: my.server.com, request: "POST / HTTP/1.1", upstream: "https://LegacyService/", host: "my.server.com"

I'd like to understand why this change is happening and see if there's anything that can be done. Am I misreading the error message?

Michael Hampton avatar
cz flag
This seems like it should work. Is that the only message you received? If you received others, post them all.
sn flag
a p
Sure, I'll see if there are others and edit them in if so.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.