Opened 8 years ago

Last modified 8 years ago

#1179 new enhancement

Allow upstreams to be resolved using internal ngx resolver instead of getaddrinfo()

Reported by: hrak@… Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.11.x
Keywords: resolver upstream Cc:
uname -a: Linux devp-apigw 4.2.0-42-generic #49~14.04.1-Ubuntu SMP Wed Jun 29 20:22:11 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: openresty/1.11.2.2
built by gcc 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
built with OpenSSL 1.0.1f 6 Jan 2014
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx/nginx --with-cc-opt='-O2 -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --add-module=../ngx_devel_kit-0.3.0 --add-module=../iconv-nginx-module-0.14 --add-module=../echo-nginx-module-0.60 --add-module=../xss-nginx-module-0.05 --add-module=../ngx_coolkit-0.2rc3 --add-module=../set-misc-nginx-module-0.31 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.06 --add-module=../srcache-nginx-module-0.31 --add-module=../ngx_lua-0.10.7 --add-module=../ngx_lua_upstream-0.06 --add-module=../headers-more-nginx-module-0.32 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.17 --add-module=../redis2-nginx-module-0.13 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.14 --add-module=../rds-csv-nginx-module-0.07 --with-ld-opt='-Wl,-rpath,/usr/share/nginx/luajit/lib -Wl,-Bsymbolic-functions -Wl,-z,relro' --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-http_realip_module --with-ipv6 --with-file-aio --with-libatomic --with-pcre=/build/pcre-8.39 --with-pcre-jit --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --user=www-data --group=www-data

Description

ngx_http_upstream_server currently uses ngx_parse_url() to parse the upstream server. ngx_parse_url() uses ngx_inet_resolve_host() to resolve the upstream server address, which in turn uses getaddrinfo() to resolve the hostname.

This causes nginx to only use the system resolvers to resolve upstream hostnames during startup.

It would be nice if it is possible to have ngx_parse_inet_url() consider/use any already configured resolvers configured by ngx_http_core's resolver directive.

Change History (1)

comment:1 by Ruslan Ermilov, 8 years ago

Resolvers are configured as part of the configuration process. Even not taking this into account, the resolver directive itself accepts a hostname argument which creates a chiken-and-egg problem with your approarch. Consider this snippet:

    resolver localhost;

    upstream u1 {
        server example.com;
    }

    resolver 8.8.8.8;

    upstream u2 {
        server example.org;
    }

So localhost should be resolved using the system's resolver, example.com using the resolved localhost, and example.org using both localhost and 8.8.8.8?

Note: See TracTickets for help on using tickets.