Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx keepalive and dns resolver

Tags:

nginx

dns

I have a nginx instance in AWS that has upstream Application layer.

There are two requirements for nginx
- keepalive
- use resolver to dynamically resolve the upstream

I am able to make either of them work.

Here is the config for making keepalive work:

upstream "backend" {
    server "appserver.example.com:443";
    keepalive 250;
}

server {           
    resolver 10.0.0.2 valid=60s;
    server_name _;
    location / {
                proxy_http_version 1.1;
                proxy_pass https://backend;
    }
}

Here is the config for DNS resolver to work:

 server {           
    resolver 10.0.0.2 valid=60s;
    server_name _;
    set $backend appserver.example.com:443;
    location / {
                proxy_http_version 1.1;
                proxy_pass https://$backend;
    }
}

How can I get both DNS resolver and keepalive to work without using a third-party plugin in open source NGinx

like image 294
Hector Avatar asked Sep 10 '16 01:09

Hector


People also ask

What is NGINX keepalive?

In Nginx, keepalive is a directive that is utilized for keeping the connection open for a certain number of requests to the server or until the request timeout period has expired.

Does NGINX cache DNS?

NGINX caches the DNS records until the next restart or configuration reload, ignoring the records' TTL values.

How does NGINX resolve upstream?

Upstream Domain Resolve¶ Its buffer has the latest IPs of the backend domain name and it integrates with the configured load balancing algorithm (least_conn, hash, etc) or the built in round robin if none is explicitly defined. At every interval (one second by default), it resolves the domain name.

How does NGINX resolver work?

Nginx is a multiplexing server (many connections in one OS process), so each call of system resolver will stop processing all connections till the resolver answer is received. That's why Nginx implemented its own internal non-blocking resolver.


Video Answer


1 Answers

According to this Nginx wiki page there seems to be the jdomain Plugin

http {
    resolver 8.8.8.8;
    resolver_timeout 10s;

    upstream backend {
        jdomain  www.baidu.com;
        # keepalive 10;
    }
    server {
        listen       8080;

        location / {
            proxy_pass http://backend;
        }
    }
}
like image 167
luckydonald Avatar answered Sep 21 '22 11:09

luckydonald