Hi,

On 18/04/2023 13:58, mailingl...@unix-solution.de 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" erro

The config looks like:

server {
     server_name foobar.example.com
...
    location / {
       resolver 127.0.0.53 valid=10s;
       ...
       proxy_pass http://container;

You need to use a variable in the proxy_pass here instead to do dynamic proxy pass. This force nginx to re-resolve the hostname. The variable's value should be set the target hostname (looks like it's 'containers' from your config).

something like
set $container_hostname 'containers';
proxy_pass http://$containers_hostname;

Note, you can't target an upstream server group with this technique - it has to be a hostname that the dns resolver returns.

If you need more advanced re-resolving, such as the ability to use upstream server groups and resolve servers within it, NGINX Plus has this feature.

In fact the patches from NGINX Plus that do the dynamic re-resolving are already on the devel mailing list - just not integrated.

https://mailman.nginx.org/pipermail/nginx-devel/2023-February/4MCLSVRK7EX6DNKHFZN6CA4SKZUSA3GA.html

So it can also be obtained by comping from source with that set of patches applied.

This is another alternative upstream resolver - although not as good, as it requires requests to initiate a re-resolve.

https://www.nginx.com/resources/wiki/modules/domain_resolve/

    }
}

nginx is 1.1.18 so it should work as documented in http://nginx.org/en/docs/http/ngx_http_core_module.html#resolver The workaround there https://stackoverflow.com/questions/42720618/docker-nginx-stopped-emerg-11-host-not-found-in-upstream/52319161#52319161 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?
Best Regards
_______________________________________________
nginx mailing list
nginx@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx
_______________________________________________
nginx mailing list
nginx@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx

Reply via email to