6

When nginx proxy_pass is a dynamic value expected to be build by substituting hostname part in URL, nginx is failing to proxy request with error: no resolver defined to resolve service where service=$1. Instead of trying to resolve service.abcd.local, it seems it is trying to resolve just service. Is there solution to this ?

location ~ ^/(.*)/(.*)$ {
  proxy_pass http://$1.abcd.local/$1/$2;   
}
5
  • have you added a resolver (resolver directive)? Commented May 10, 2016 at 11:01
  • BTW, for url like /a/b/c/d your regexp will result in $1 = /a/b/c, $2 = d, and proxy url will be http://a/b/c/.abcd.local/...., and nginx absolutely right to try to resolve hostname a. Commented May 10, 2016 at 11:04
  • Alexey - Thanks. That is correct. regex was wrong. After fixing regex, still it is failing attempting to resolve service.abcd.local. If proxy_pass is hardcoded as service.abcd.local nginx is resolving and is able to proxy. Commented May 10, 2016 at 12:00
  • And again, have you added resolver? Commented May 10, 2016 at 12:01
  • No - is explicit resolver required ? nginx is running in amazon VPC with *.abcd.local resolving. Commented May 10, 2016 at 12:04

1 Answer 1

7

As specified in nginx's doc proxy_pass:

A server name, its port and the passed URI can also be specified using variables:

proxy_pass http://$host$uri;

[…]

In this case, the server name is searched among the described server groups, and, if not found, is determined using a resolver.

Sign up to request clarification or add additional context in comments.

3 Comments

So this means if a variable is present in proxy_pass, a resolver has to be explicitly specified ?
Yes, if variable present in host part. Or, you have to define server group for all possible hosts.
That clarifies things. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.