resolver does not work

Maxim Dounin mdounin at
Tue Apr 18 19:29:24 UTC 2023


On Tue, Apr 18, 2023 at 02:58:08PM +0200, mailinglist at wrote:

> Hello,
> I have a nginx proxy in front of systemd-nspawn containers.
> The IP's of the containers are dynamic.
> When I start nginx *after* the  containers it works.
> When the IP of the container is changed while nginx is running i get a 
> "Bad Gateway" error.
> The config looks like:
> server {
>      server_name
> ...
>     location / {
>        resolver valid=10s;
>        ...
>        proxy_pass http://container;
>     }
> }
> nginx is 1.1.18 so it should work as documented in 
> The workaround there 
> doesn't work.
> I have also try to config a upstream backend and the resolver in the 
> server part or in the http part.
> The errors are: "upstream timed out" or "container could not be resolved 
> (3: Host not found)"
> Whats wrong there?

The "resolver" directive is only used when the "proxy_pass" 
directive contain variables, and therefore nginx isn't able to 
determine upstream addresses when parsing configuration.  Quoting

: Parameter value can contain variables. In this case, if an 
: address is specified as a domain name, the name is searched among 
: the described server groups, and, if not found, is determined 
: using a resolver.

The "workaround", however, should work fine.  Something like this 
should be enough:

        resolver valid=10s;
        set $upstream "http://container";
        proxy_pass $upstream;

Note though that there should be an actual DNS name which can be 
resolved with the DNS server configured with the "resolver" 
directive.  The "container could not be resolved (3: Host not 
found)" error suggests that your DNS server does not return 
anything for the name - you may want to dig further into systemd 
to find out why it doesn't return anything.

Maxim Dounin

More information about the nginx mailing list