{"id":1655,"date":"2025-04-22T19:33:16","date_gmt":"2025-04-22T17:33:16","guid":{"rendered":"https:\/\/olvas.dev\/?p=1655"},"modified":"2025-04-22T19:33:16","modified_gmt":"2025-04-22T17:33:16","slug":"%d0%ba%d0%be%d1%80%d0%be%d1%82%d0%ba%d0%be-%d0%be-dns-%d0%b2-nginx","status":"publish","type":"post","link":"https:\/\/olvas.dev\/?p=1655","title":{"rendered":"\u041a\u043e\u0440\u043e\u0442\u043a\u043e \u043e DNS \u0432 NGINX"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">\u041a\u0430\u043a DNS \u0432\u043e\u043e\u0431\u0449\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 Linux (\u0438 \u043f\u043e\u0447\u0435\u043c\u0443 \u044d\u0442\u043e \u0432\u0430\u0436\u043d\u043e \u0434\u043b\u044f NGINX)<\/h3>\n\n\n\n<p>\u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043f\u0440\u043e&nbsp;<code>proxy_pass<\/code>&nbsp;\u0432&nbsp;NGINX, \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c,&nbsp;<strong>\u0447\u0435\u0440\u0435\u0437 \u043a\u0430\u043a\u043e\u0439 \u0438\u043c\u0435\u043d\u043d\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0440\u0435\u0437\u043e\u043b\u0432\u044f\u0442\u0441\u044f \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0435 \u0438\u043c\u0435\u043d\u0430<\/strong>, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e&nbsp;\u043e\u0442&nbsp;\u044d\u0442\u043e\u0433\u043e \u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u043a\u0435\u0448\u0438, \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u0440\u0438&nbsp;\u0441\u0431\u043e\u044f\u0445, \u0440\u0435\u0430\u043a\u0446\u0438\u044f \u043d\u0430&nbsp;\u0441\u043c\u0435\u043d\u0443 IP \u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e\u0441\u0442\u044c \u0432\u0441\u0435\u0433\u043e \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430.<\/p>\n\n\n\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u0441&nbsp;\u0447\u0435\u0433\u043e \u043d\u0430\u0434\u043e \u043d\u0430\u0447\u0430\u0442\u044c: NGINX&nbsp;\u2014 \u043d\u0435&nbsp;\u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0440\u043e\u043a\u0441\u0438. \u041e\u043d \u043d\u0435&nbsp;\u0430\u0431\u0441\u0442\u0440\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u043d \u043e\u0442&nbsp;\u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u041e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432&nbsp;\u0440\u0430\u043c\u043a\u0430\u0445 \u041e\u0421, \u0438 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0435\u0433\u043e DNS\u2011\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442&nbsp;\u0442\u043e\u0433\u043e,&nbsp;<strong>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435&nbsp;\u043b\u0438 \u0432\u044b \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0432&nbsp;<\/strong><code><strong>proxy_pass<\/strong><\/code><strong>&nbsp;\u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0435&nbsp;\u043b\u0438&nbsp;<\/strong><code><strong>resolver<\/strong><\/code>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u0414\u0432\u0430 \u0440\u0435\u0436\u0438\u043c\u0430 \u0440\u0435\u0437\u043e\u043b\u0432\u0438\u043d\u0433\u0430<\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>\u0421\u0446\u0435\u043d\u0430\u0440\u0438\u0439<\/th><th>\u0427\u0442\u043e&nbsp;\u0434\u0435\u043b\u0430\u0435\u0442 NGINX<\/th><th>\u0427\u0435\u0440\u0435\u0437 \u0447\u0442\u043e&nbsp;\u0440\u0435\u0437\u043e\u043b\u0432\u0438\u0442<\/th><\/tr><tr><td><code>proxy_pass http:\/\/example.com;<\/code>&nbsp;\u0431\u0435\u0437&nbsp;<code>resolver<\/code>&nbsp;\u0438 \u0431\u0435\u0437&nbsp;\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445<\/td><td>\u041e\u0434\u043d\u043e\u043a\u0440\u0430\u0442\u043d\u044b\u0439 \u0440\u0435\u0437\u043e\u043b\u0432\u0438\u043d\u0433 \u043f\u0440\u0438&nbsp;\u0441\u0442\u0430\u0440\u0442\u0435 (\u0438\u043b\u0438 reload)<\/td><td>\u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0441\u0442\u0435\u043a, \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e&nbsp;<code>gethostbyname()<\/code><\/td><\/tr><tr><td><code>proxy_pass http:\/\/$backend;<\/code>&nbsp;+&nbsp;<code>resolver<\/code><\/td><td>\u0420\u0435\u0437\u043e\u043b\u0432\u0438\u043d\u0433 \u043f\u0440\u0438&nbsp;\u043a\u0430\u0436\u0434\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0438\u043b\u0438&nbsp;\u043f\u043e&nbsp;<code>valid=<\/code><\/td><td>\u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0439 DNS\u2011\u043a\u043b\u0438\u0435\u043d\u0442 NGINX<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u0412&nbsp;\u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 NGINX \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0440\u0435\u0437\u043e\u043b\u0432\u0435\u0440, \u0430&nbsp;\u0437\u043d\u0430\u0447\u0438\u0442:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u0447\u0438\u0442\u0430\u0435\u0442\u00a0<code>\/etc\/resolv.conf<\/code><\/li>\n\n\n\n<li>\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u00a0<code>nsswitch.conf<\/code>\u00a0\u0438 \u043c\u043e\u0436\u0435\u0442 \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a\u00a0\u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u043c \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430\u043c (<code>libnss_mdns<\/code>,\u00a0<code>libnss_resolve<\/code>)<\/li>\n\n\n\n<li>\u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c IP \u0438\u0437\u00a0\u043a\u0435\u0448\u0430\u00a0<code>systemd-resolved<\/code>,\u00a0<code>nscd<\/code>\u00a0\u0438\u043b\u0438\u00a0<code>dnsmasq<\/code>, \u0435\u0441\u043b\u0438 \u0442\u0430\u043a \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043e<\/li>\n\n\n\n<li>\u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432\u0430\u0440\u044c\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043e\u0442\u00a0\u0434\u0438\u0441\u0442\u0440\u0438\u0431\u0443\u0442\u0438\u0432\u0430 \u043a\u00a0\u0434\u0438\u0441\u0442\u0440\u0438\u0431\u0443\u0442\u0438\u0432\u0443<\/li>\n<\/ul>\n\n\n\n<p>\u0412&nbsp;\u044d\u0442\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435, \u0435\u0441\u043b\u0438 IP \u0443&nbsp;\u0434\u043e\u043c\u0435\u043d\u0430&nbsp;<code>example.com<\/code>&nbsp;\u043f\u043e\u043c\u0435\u043d\u044f\u043b\u0441\u044f&nbsp;\u2014 NGINX \u043e\u0431&nbsp;\u044d\u0442\u043e\u043c \u043d\u0435&nbsp;\u0443\u0437\u043d\u0430\u0435\u0442. \u041e\u043d \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441&nbsp;IP, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u043f\u0440\u0438&nbsp;\u0441\u0442\u0430\u0440\u0442\u0435.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b \u043f\u0438\u0448\u0435\u0442\u0435:<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>resolver<\/strong> 8.8.8.<strong>8 valid<\/strong>=10s;<\/code><\/pre>\n\n\n\n<p>\u2014 \u0432\u0441\u0451 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f.<\/p>\n\n\n\n<p>\u0422\u0435\u043f\u0435\u0440\u044c NGINX:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u043d\u0435\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 glibc<\/strong>;<\/li>\n\n\n\n<li><strong>\u043d\u0435\u00a0\u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043a\u00a0\u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u043c\u0443 \u043a\u0435\u0448\u0443<\/strong>;<\/li>\n\n\n\n<li><strong>\u0434\u0435\u043b\u0430\u0435\u0442 DNS\u2011\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0441\u0430\u043c<\/strong>, \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0447\u0435\u0440\u0435\u0437 UDP \u043d\u0430\u00a0\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439\u00a0<code>resolver<\/code>;<\/li>\n\n\n\n<li><strong>\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 IP \u043a\u0435\u0448\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0440\u043e\u0432\u043d\u043e \u043d\u0430\u00a0<\/strong><code><strong>valid=5s<\/strong><\/code>, \u0437\u0430\u0442\u0435\u043c \u0440\u0435\u0437\u043e\u043b\u0432\u044f\u0442\u0441\u044f \u0437\u0430\u043d\u043e\u0432\u043e.<\/li>\n<\/ul>\n\n\n\n<p>\u042d\u0442\u043e \u0432&nbsp;\u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043d\u0443\u0436\u043d\u043e, \u0435\u0441\u043b\u0438 \u0432\u0430\u0448\u0438 backend\u2011\u0441\u0435\u0440\u0432\u0438\u0441\u044b \u0436\u0438\u0432\u0443\u0442 \u0437\u0430&nbsp;\u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u043e\u043c, \u0432&nbsp;\u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0438 (Kubernetes, Nomad, Docker Swarm \u0438&nbsp;\u0442.&nbsp;\u043f.), \u0438\u043b\u0438&nbsp;\u0432\u043e\u043e\u0431\u0449\u0435 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 \u043d\u043e\u0432\u044b\u0435 IP \u043f\u043e&nbsp;SRV\u2011\u0437\u0430\u043f\u0438\u0441\u044f\u043c (\u043a\u043e\u0442\u043e\u0440\u044b\u0435, \u043a\u0441\u0442\u0430\u0442\u0438, NGINX \u043d\u0435&nbsp;\u0443\u043c\u0435\u0435\u0442).<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u0413\u043b\u0430\u0432\u043d\u043e\u0435, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043f\u043e\u043c\u043d\u0438\u0442\u044c<\/h4>\n\n\n\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435, \u0447\u0442\u043e\u0431\u044b NGINX&nbsp;<strong>\u043d\u0430&nbsp;\u043b\u0435\u0442\u0443 \u043f\u043e\u0434\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u043b \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f IP \u0443&nbsp;\u0434\u043e\u043c\u0435\u043d\u0430<\/strong>&nbsp;\u2014 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u0423\u043a\u0430\u0437\u0430\u0442\u044c\u00a0<code>resolver<\/code>;<\/li>\n\n\n\n<li>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0432\u00a0<code>proxy_pass<\/code>.<\/li>\n<\/ol>\n\n\n\n<p>\u0411\u0435\u0437&nbsp;\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445&nbsp;\u2014 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e\u043a\u0440\u0430\u0442\u043d\u044b\u0439 \u0440\u0435\u0437\u043e\u043b\u0432\u0438\u043d\u0433 \u043f\u0440\u0438&nbsp;\u0441\u0442\u0430\u0440\u0442\u0435.<\/p>\n\n\n\n<p>\u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435, \u043c\u043e\u0433\u0443 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0435\u043a\u0446\u0438\u044e \u043f\u0440\u043e&nbsp;\u0442\u043e, \u043a\u0430\u043a&nbsp;\u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u043a\u0430\u043a\u043e\u0439 \u0438\u043c\u0435\u043d\u043d\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0441\u0435\u0439\u0447\u0430\u0441 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432&nbsp;\u0432\u0430\u0448\u0435\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438&nbsp;\u2014 \u0441&nbsp;<code>strace<\/code>,&nbsp;<code>lsof<\/code>,&nbsp;<code>tcpdump<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">DNS-\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0433\u043b\u0430\u0437\u0430\u043c\u0438 NGINX<\/h3>\n\n\n\n<p>\u041a\u043e\u0433\u0434\u0430 \u0432\u044b \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0435:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>resolver<\/strong> 1.1.1.<strong>1 valid<\/strong>=5s;<br><br><strong>server<\/strong> {<br>    <strong>listen<\/strong> 80;<br>    <strong>location<\/strong> \/ {<br>        <strong>set<\/strong> $up backend.local;<br>        <strong>proxy_pass<\/strong> <strong>http<\/strong>:\/\/$up;<br>    }<br>}<\/code><\/pre>\n\n\n\n<p>NGINX \u043f\u0440\u0438&nbsp;\u043f\u0435\u0440\u0432\u043e\u043c \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u043a&nbsp;\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0432&nbsp;<code>proxy_pass<\/code>&nbsp;\u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 UDP\u2011\u0437\u0430\u043f\u0440\u043e\u0441 \u0442\u0438\u043f\u0430 A (\u0438\u043b\u0438 AAAA, \u0435\u0441\u043b\u0438 IPv6&nbsp;\u043d\u0435&nbsp;\u043e\u0442\u043a\u043b\u044e\u0447\u0451\u043d).<\/p>\n\n\n\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 DNS\u2011\u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u0435\u043b\u0430\u0435\u0442 NGINX:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo tcpdump -n port 53 -i any and udp<\/code><\/pre>\n\n\n\n<p>\u041e\u0442\u0432\u0435\u0442 \u043a\u0435\u0448\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0440\u043e\u0432\u043d\u043e \u043d\u0430&nbsp;<code>valid=X<\/code>&nbsp;\u0441\u0435\u043a\u0443\u043d\u0434. \u0412&nbsp;\u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0435&nbsp;\u0431\u0443\u0434\u0435\u0442. \u041f\u043e&nbsp;\u0438\u0441\u0442\u0435\u0447\u0435\u043d\u0438\u0438 \u0441\u0440\u043e\u043a\u0430&nbsp;\u2014 \u0440\u0435\u0437\u043e\u043b\u0432\u0438\u0442\u0441\u044f \u0437\u0430\u043d\u043e\u0432\u043e.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u041f\u0440\u0438\u043c\u0435\u0440 \u043e\u0442\u043b\u0430\u0434\u043a\u0438 \u0440\u0435\u0437\u043e\u043b\u0432\u0438\u043d\u0433\u0430<\/h3>\n\n\n\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0435\u0441\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>resolver<\/strong> 1.1.1.<strong>1 valid<\/strong>=5s;<br><br><strong>server<\/strong> {<br>    <strong>listen<\/strong> 80;<br>    <strong>location<\/strong> \/ {<br>        <strong>set<\/strong> $up backend.local;<br>        <strong>proxy_pass<\/strong> <strong>http<\/strong>:\/\/$up;<br>    }<br>}<\/code><\/pre>\n\n\n\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442&nbsp;\u043b\u0438 \u0440\u0435\u0437\u043e\u043b\u0432\u0438\u043d\u0433 \u043a\u0430\u043a&nbsp;\u043d\u0430\u0434\u043e, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c&nbsp;<code>tcpdump<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo tcpdump -n port 53 -i any and udp<\/code><\/pre>\n\n\n\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441&nbsp;\u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0430:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl http:\/\/localhost\/<\/code><\/pre>\n\n\n\n<p>\u041c\u044b \u0443\u0432\u0438\u0434\u0438\u043c DNS\u2011\u0437\u0430\u043f\u0440\u043e\u0441 \u043e\u0442&nbsp;NGINX \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043a 1.1.1.1. \u042d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c \u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u044f\u043c\u043e\u0439 \u0440\u0435\u0437\u043e\u043b\u0432\u0438\u043d\u0433.<\/p>\n\n\n\n<p>\u0415\u0441\u043b\u0438&nbsp;<code>valid=5s<\/code>, \u0438 \u0432\u044b \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u0435 curl \u0432&nbsp;\u0442\u0435\u0447\u0435\u043d\u0438\u0435 5&nbsp;\u0441\u0435\u043a\u0443\u043d\u0434&nbsp;\u2014 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0435&nbsp;\u0431\u0443\u0434\u0435\u0442. \u0415\u0441\u043b\u0438 \u043f\u043e\u0437\u0436\u0435&nbsp;\u2014 \u0431\u0443\u0434\u0435\u0442 \u043d\u043e\u0432\u044b\u0439.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u041a\u0430\u043a\u0438\u0435 \u0442\u0438\u043f\u044b DNS-\u0437\u0430\u043f\u0438\u0441\u0435\u0439 NGINX \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442?<\/h3>\n\n\n\n<p>\u0421\u043f\u0438\u0441\u043e\u043a \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u0435\u043d:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>A <\/code>(IPv4)<\/li>\n\n\n\n<li><code>AAAA <\/code>(IPv6, \u0435\u0441\u043b\u0438 \u043d\u0435\u00a0\u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u043e)<\/li>\n<\/ul>\n\n\n\n<p>CNAME&nbsp;\u2014 \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u043e\u043d \u0440\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u043e&nbsp;A\/AAAA (\u0447\u0442\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u0434\u0435\u043b\u0430\u0435\u0442 DNS\u2011\u0441\u0435\u0440\u0432\u0435\u0440). SRV, TXT, MX \u0438 \u043f\u0440\u043e\u0447\u0435\u0435&nbsp;\u2014 \u043d\u0435&nbsp;\u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e. \u0415\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 service discovery, \u0433\u0434\u0435 backend \u043e\u0442\u0434\u0430\u0451\u0442\u0441\u044f \u043a\u0430\u043a&nbsp;SRV\u2011\u0437\u0430\u043f\u0438\u0441\u044c (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432&nbsp;Consul \u0438\u043b\u0438&nbsp;Kubernetes), \u0432\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0440\u0435\u0437\u043e\u043b\u0432\u0435\u0440 \u0438\u043b\u0438&nbsp;\u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u044b\u0439 \u043f\u0440\u043e\u043a\u0441\u0438.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u0427\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u0438 \u043e\u0448\u0438\u0431\u043a\u0435 DNS?<\/h3>\n\n\n\n<p>\u0415\u0441\u043b\u0438 DNS \u043d\u0435&nbsp;\u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442, \u0438\u043b\u0438&nbsp;NGINX \u043d\u0435&nbsp;\u043c\u043e\u0436\u0435\u0442 \u0435\u0433\u043e \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u044c&nbsp;\u2014 \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c 502&nbsp;Bad Gateway. \u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http {<br>    resolver 8.8.8.8 1.1.1.1 valid=5s ipv6=off;<br>    resolver_timeout 2s;<br><br>    map $upstream_http_x_healthcheck $backend_host {<br>        default \"api-primary.example.com\";<br>        \"fail\" \"api-fallback.example.com\";<br>    }<br><br>    server {<br>        listen 80;<br><br>        location \/api\/ {<br>            proxy_pass http:\/\/$backend_host;<br>            proxy_http_version 1.1;<br>            proxy_set_header Connection \"\";<br>        }<br>    }<br>}<\/code><\/pre>\n\n\n\n<p>\u0427\u0442\u043e\u0431\u044b \u0441\u043c\u044f\u0433\u0447\u0438\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u044f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>resolver_timeout<\/strong> 2s;<br><strong>proxy_next_upstream<\/strong> <strong>error timeout<\/strong> <strong>invalid_header http_500<\/strong> <strong>http_502 http_503<\/strong>;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u0441 DNS \u0438 fallback<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>http<\/strong> {<br>    <strong>resolver<\/strong> 8.8.8.8 1.1.1.1 valid=5s ipv6=off;<br>    <strong>resolver_timeout<\/strong> 2s;<br><br>    <strong>map<\/strong> $upstream_http_x_healthcheck $backend_host {<br>        default \"api-primary.example.com\";<br>        \"fail\" \"api-fallback.example.com\";<br>    }<br><br>    <strong>server<\/strong> {<br>        <strong>listen<\/strong> 80;<br><br>        <strong>location<\/strong> \/api\/ {<br>            <strong>proxy_pass<\/strong> <strong>http<\/strong>:\/\/$backend_host;<br>            proxy_http_version 1.1;<br>            <strong>proxy_set_header<\/strong> Connection \"\";<br>        }<br>    }<br>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0441 Kubernetes \u0447\u0435\u0440\u0435\u0437 headless service<\/h3>\n\n\n\n<p>Kubernetes \u043d\u0435&nbsp;\u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u043a\u0443 \u0447\u0435\u0440\u0435\u0437 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 DNS, \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 headless\u2011\u0441\u0435\u0440\u0432\u0438\u0441:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: myapp-headless<br>spec:<br>  clusterIP: None<br>  selector:<br>    app: myapp<br>  ports:<br>    - port: 80<\/code><\/pre>\n\n\n\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 DNS\u2011\u0437\u0430\u043f\u0440\u043e\u0441 \u043a&nbsp;<code>myapp-headless.default.svc.cluster.local<\/code>&nbsp;\u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c&nbsp;<strong>\u0432\u0441\u0435 IP \u043f\u043e\u0434\u043e\u0432<\/strong>.<\/p>\n\n\n\n<p>NGINX \u0443\u043c\u0435\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e&nbsp;<strong>\u043e\u0434\u0438\u043d<\/strong>&nbsp;\u0438\u0437&nbsp;\u043d\u0438\u0445. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438&nbsp;\u043a\u0430\u0436\u0434\u043e\u043c \u043d\u043e\u0432\u043e\u043c \u0440\u0435\u0437\u043e\u043b\u0432\u0438\u043d\u0433\u0435 (\u043f\u043e&nbsp;<code>valid=5s<\/code>) \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u043e\u0434, \u043d\u043e&nbsp;\u043d\u0435&nbsp;\u0432\u0441\u0435 \u0441\u0440\u0430\u0437\u0443.<\/p>\n\n\n\n<p>\u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0432\u0441\u0435\u043c\u0438&nbsp;\u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0432\u043d\u0435\u0448\u043d\u0438\u0439&nbsp;<code>sidecar<\/code>&nbsp;\u0438\u043b\u0438&nbsp;<code>nginx+lua<\/code>&nbsp;\u0441&nbsp;round\u2011robin \u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u0432\u0440\u0443\u0447\u043d\u0443\u044e.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u041a\u0430\u043a NGINX \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 IP, \u0435\u0441\u043b\u0438 DNS \u043e\u0442\u0434\u0430\u0451\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e?<\/h3>\n\n\n\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, DNS \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>A 10.0.0.1<br>A 10.0.0.2<br>A 10.0.0.3<\/code><\/pre>\n\n\n\n<p>NGINX \u0432\u043e\u0437\u044c\u043c\u0451\u0442&nbsp;<strong>\u043f\u0435\u0440\u0432\u044b\u0439 \u0438\u0437&nbsp;\u0441\u043f\u0438\u0441\u043a\u0430<\/strong>. \u0415\u0441\u043b\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043d\u0435&nbsp;\u0443\u0434\u0430\u043b\u043e\u0441\u044c, \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0438\u0442\u0441\u044f \u043d\u0430&nbsp;\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439. \u041f\u0440\u0438&nbsp;\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0440\u0435\u0437\u043e\u043b\u0432\u0438\u043d\u0433\u0435&nbsp;\u2014 \u0441\u043d\u043e\u0432\u0430 \u043f\u0435\u0440\u0432\u044b\u0439. \u042d\u0442\u043e \u043d\u0435&nbsp;\u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u043a\u0430, \u044d\u0442\u043e fallback.<\/p>\n\n\n\n<p>\u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u0430 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0430\u044f \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u043a\u0430&nbsp;\u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c&nbsp;<code>upstream<\/code>&nbsp;\u0441&nbsp;IP\u2011\u0448\u0430\u0440\u0434\u0438\u043d\u0433\u043e\u043c \u0437\u0430\u0440\u0430\u043d\u0435\u0435:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>upstream<\/strong> <strong>dynamic_backend <\/strong>{<br>    <strong>server<\/strong> 10.0.0.1;<br>    <strong>server<\/strong> 10.0.0.2;<br>    <strong>server<\/strong> 10.0.0.3;<br>}<br><br><strong>proxy_pass<\/strong> <strong>http<\/strong>:\/\/dynamic_backend;<\/code><\/pre>\n\n\n\n<p>\u041d\u043e&nbsp;\u0442\u0443\u0442 \u043d\u0443\u0436\u0435\u043d \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u0441\u043a\u0440\u0438\u043f\u0442\/\u0441\u0435\u0440\u0432\u0438\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442 \u044d\u0442\u043e\u0442 \u0441\u043f\u0438\u0441\u043e\u043a.<\/p>\n\n\n\n<p>\u0412\u043e\u0442 \u0442\u0440\u0438 \u043f\u043b\u043e\u0442\u043d\u044b\u0445 \u0438 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0430\u0441\u044b\u0449\u0435\u043d\u043d\u044b\u0445 \u0431\u043b\u043e\u043a\u0430, \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u043e&nbsp;\u0437\u0430\u044f\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0442\u0435\u043c\u0435. \u041d\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u0432&nbsp;\u0435\u0434\u0438\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435 \u0441\u0442\u0430\u0442\u044c\u0438&nbsp;\u2014 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e, \u0433\u043b\u0443\u0431\u043e\u043a\u043e \u0438 \u043f\u043e&nbsp;\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443, \u0441&nbsp;\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u043c\u0438 \u00ab\u043e\u0442 \u0441\u0442\u0430\u0440\u0448\u0435\u0433\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u00bb.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Edge-\u043a\u0435\u0439\u0441\u044b \u0441 DNS-over-TCP<\/h3>\n\n\n\n<p>\u041f\u043e&nbsp;\u0434\u0435\u0444\u043e\u043b\u0442\u0443 NGINX \u0434\u0435\u043b\u0430\u0435\u0442 DNS\u2011\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0447\u0435\u0440\u0435\u0437 UDP. \u042d\u0442\u043e&nbsp;\u0431\u044b\u0441\u0442\u0440\u043e \u0438 \u0434\u0435\u0448\u0435\u0432\u043e. \u041d\u043e&nbsp;\u0435\u0441\u0442\u044c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 UDP&nbsp;\u2014 \u043d\u0435\u043d\u0430\u0434\u0451\u0436\u0435\u043d: \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0434\u043b\u0438\u043d\u043d\u044b\u0435 \u043e\u0442\u0432\u0435\u0442\u044b (\u0431\u043e\u043b\u044c\u0448\u0435 512&nbsp;\u0431\u0430\u0439\u0442 \u0431\u0435\u0437&nbsp;EDNS), \u0438\u043b\u0438&nbsp;\u043e\u0442\u043a\u0430\u0437 \u0441\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u044b DNS\u2011\u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0441&nbsp;\u0444\u043b\u0430\u0433\u043e\u043c&nbsp;<code>TC<\/code>. \u0412&nbsp;\u0442\u0430\u043a\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e&nbsp;\u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 RFC 1035&nbsp;\u043a\u043b\u0438\u0435\u043d\u0442 \u0434\u043e\u043b\u0436\u0435\u043d&nbsp;<strong>\u043f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0447\u0435\u0440\u0435\u0437 TCP<\/strong>.<\/p>\n\n\n\n<p><strong>NGINX \u044d\u0442\u043e\u0433\u043e \u043d\u0435&nbsp;\u0434\u0435\u043b\u0430\u0435\u0442.<\/strong><\/p>\n\n\n\n<p>\u0412\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 DNS\u2011\u0440\u0435\u0437\u043e\u043b\u0432\u0435\u0440 NGINX&nbsp;<strong>\u043d\u0435&nbsp;\u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 fallback \u043d\u0430&nbsp;TCP<\/strong>, \u0438 \u0434\u0430\u0436\u0435&nbsp;<strong>\u043d\u0435&nbsp;\u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 EDNS (\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f DNS)<\/strong>. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e&nbsp;\u0435\u0441\u043b\u0438 DNS\u2011\u0441\u0435\u0440\u0432\u0435\u0440 \u043e\u0442\u0434\u0430\u0451\u0442 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043e\u0442\u0432\u0435\u0442, \u0438\u043b\u0438&nbsp;\u043e\u0431\u0440\u0435\u0437\u0430\u0435\u0442 \u0435\u0433\u043e&nbsp;\u2014 \u0432\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 \u043e\u0448\u0438\u0431\u043a\u0443&nbsp;<code>502 Bad Gateway<\/code>&nbsp;\u0432&nbsp;NGINX, \u0438 \u0432\u0441\u0451.<\/p>\n\n\n\n<p>\u041f\u0440\u0438\u043c\u0435\u0440, \u0433\u0434\u0435 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u0423\u00a0\u0432\u0430\u0441\u00a0<code>example.com<\/code>, \u0430\u00a0\u0432\u00a0\u043e\u0442\u0432\u0435\u0442\u0435\u00a0\u2014 20\u00a0A\u2011\u0437\u0430\u043f\u0438\u0441\u0435\u0439 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0442\u00a0SRV\u2011\u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430).<\/li>\n\n\n\n<li>\u041e\u0442\u0432\u0435\u0442 > 512\u00a0\u0431\u0430\u0439\u0442.<\/li>\n\n\n\n<li>DNS\u2011\u0441\u0435\u0440\u0432\u0435\u0440 \u043e\u0431\u0440\u0435\u0437\u0430\u0435\u0442 \u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u00a0<code>\u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0440\u043e\u0441\u0438 \u043f\u043e TCP<\/code>.<\/li>\n\n\n\n<li>\u0410\u00a0NGINX \u043d\u0435\u00a0\u043c\u043e\u0436\u0435\u0442.<\/li>\n<\/ul>\n\n\n\n<p>\u0415\u0441\u043b\u0438 \u0432\u0430\u0448 DNS \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u0434\u0430\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043e\u0442\u0432\u0435\u0442\u044b&nbsp;\u2014 \u043f\u043e\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u043f\u0435\u0440\u0435\u0434 \u043d\u0438\u043c&nbsp;<code>dnsmasq<\/code>,&nbsp;<code>CoreDNS<\/code>&nbsp;\u0438\u043b\u0438&nbsp;<code>Unbound<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0430\u0433\u0440\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0440\u0435\u0437\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442\u044b \u043a\u0430\u043a&nbsp;\u043d\u0430\u0434\u043e.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Lua-\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u0438 dns.resolver<\/h3>\n\n\n\n<p>\u0415\u0441\u043b\u0438 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0440\u0435\u0437\u043e\u043b\u0432\u0435\u0440 \u0432\u0430\u0441 \u043d\u0435&nbsp;\u0443\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442, \u0435\u0441\u0442\u044c \u0432\u044b\u0445\u043e\u0434&nbsp;\u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Lua \u0447\u0435\u0440\u0435\u0437&nbsp;<code>ngx_lua<\/code>&nbsp;(OpenResty \u0438\u043b\u0438&nbsp;NGINX \u0441&nbsp;\u043c\u043e\u0434\u0443\u043b\u0435\u043c&nbsp;<code>lua-nginx-module<\/code>).<\/p>\n\n\n\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430&nbsp;Lua, \u0433\u0434\u0435 \u0440\u0435\u0437\u043e\u043b\u0432\u0438\u043d\u0433 \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437&nbsp;<code>resty.dns.resolver<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>local<\/strong> resolver = require \"resty.dns.resolver\"<br><strong>local<\/strong> r, err = resolver:new{<br>    nameservers = {\"8.8.8.8\", \"1.1.1.1\"},<br>    retrans = 5,<br>    timeout = 2000,<br>}<br><br><strong>local<\/strong> answers, err = r:query(\"backend.example.com\", { qtype = r.TYPE_A })<br><strong>if<\/strong> <strong>not<\/strong> answers <strong>then<\/strong><br>    ngx.log(ngx.ERR, \"failed to query: \", err)<br>    <strong>return<\/strong> ngx.exit(500)<br><strong>end<\/strong><br><br><strong>for<\/strong> _, ans <strong>in<\/strong> ipairs(answers) <strong>do<\/strong><br>    <strong>if<\/strong> ans.address <strong>then<\/strong><br>        ngx.var.backend_ip = ans.address<br>        <strong>break<\/strong><br>    <strong>end<\/strong><br><strong>end<\/strong><\/code><\/pre>\n\n\n\n<p>\u0418 \u043f\u043e\u0442\u043e\u043c \u0432&nbsp;nginx.conf:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>set_by_lua_block <\/strong><strong>$backend_ip <\/strong>{<br>    -- \u043a\u043e\u0434 \u0432\u044b\u0448\u0435<br>}<br><br><strong>proxy_pass<\/strong> <strong>http<\/strong>:\/\/$backend_ip;<\/code><\/pre>\n\n\n\n<p>\u041f\u043b\u044e\u0441\u044b:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u043d\u0430\u0434 \u0440\u0435\u0437\u043e\u043b\u0432\u0438\u043d\u0433\u043e\u043c.<\/li>\n\n\n\n<li>\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0445 \u0442\u0430\u0439\u043c\u0430\u0443\u0442\u043e\u0432, TCP, EDNS.<\/li>\n\n\n\n<li>\u041c\u043e\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c retry\u2011\u043b\u043e\u0433\u0438\u043a\u0443, \u0431\u0430\u043b\u0430\u043d\u0441\u0438\u0440\u043e\u0432\u043a\u0443, SRV, \u0434\u0430\u0436\u0435 DNSSEC.<\/li>\n<\/ul>\n\n\n\n<p>\u041c\u0438\u043d\u0443\u0441\u044b:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u041d\u0443\u0436\u043d\u043e \u0441\u043e\u0431\u0440\u0430\u0442\u044c NGINX \u0441\u00a0\u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 Lua.<\/li>\n\n\n\n<li>\u041f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0447\u0443\u0442\u044c \u043d\u0438\u0436\u0435, \u0447\u0435\u043c \u0443\u00a0\u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u0435\u0437\u043e\u043b\u0432\u0435\u0440\u0430.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Per-request DNS: \u0440\u0435\u0437\u043e\u043b\u0432\u0438\u043d\u0433 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441<\/h3>\n\n\n\n<p>\u0412\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c&nbsp;<code>resolver + \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f<\/code>&nbsp;\u0432&nbsp;NGINX \u0434\u0435\u043b\u0430\u0435\u0442 DNS\u2011\u0437\u0430\u043f\u0440\u043e\u0441&nbsp;<strong>\u043d\u0435&nbsp;\u043d\u0430&nbsp;\u043a\u0430\u0436\u0434\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441<\/strong>, \u0430&nbsp;<strong>\u043f\u043e&nbsp;\u0438\u0441\u0442\u0435\u0447\u0435\u043d\u0438\u0438&nbsp;<\/strong><code><strong>valid=X<\/strong><\/code><strong>&nbsp;\u0441\u0435\u043a\u0443\u043d\u0434<\/strong>.<\/p>\n\n\n\n<p>\u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e&nbsp;<strong>\u043f\u0440\u044f\u043c \u0440\u0435\u0430\u043b\u044c\u043d\u043e DNS \u043d\u0430&nbsp;\u043a\u0430\u0436\u0434\u044b\u0439 HTTP\u2011\u0437\u0430\u043f\u0440\u043e\u0441<\/strong>&nbsp;\u2014 \u043d\u0443\u0436\u043d\u043e \u0443\u0445\u043e\u0434\u0438\u0442\u044c \u0432&nbsp;Lua \u0438\u043b\u0438&nbsp;\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043d\u0435\u0448\u043d\u0438\u0435 sidecar\u2011\u043f\u0440\u043e\u043a\u0441\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 Envoy \u0438\u043b\u0438&nbsp;custom DNS\u2011\u043a\u043b\u0438\u0435\u043d\u0442.<\/p>\n\n\n\n<p>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0430&nbsp;Lua:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>set_by_lua_block $backend_ip {<br>    <strong>local<\/strong> resolver = require \"resty.dns.resolver\"<br>    <strong>local<\/strong> r = resolver:new{ nameservers = {\"1.1.1.1\"}, timeout = 1000 }<br>    <strong>local<\/strong> a, err = r:query(\"backend.example.com\", { qtype = r.TYPE_A })<br>    <strong>if<\/strong> <strong>not<\/strong> a <strong>or<\/strong> #a == 0 <strong>then<\/strong> <strong>return<\/strong> \"127.0.0.1\" <strong>end<\/strong><br>    <strong>return<\/strong> a&#91;1].address<br>}<\/code><\/pre>\n\n\n\n<p>\u041a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u043f\u0440\u0438&nbsp;<strong>\u043a\u0430\u0436\u0434\u043e\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435<\/strong>&nbsp;(\u0435\u0441\u043b\u0438 \u0431\u043b\u043e\u043a&nbsp;<code>set_by_lua_block<\/code>&nbsp;\u0443\u043a\u0430\u0437\u0430\u043d \u0432&nbsp;<code>location<\/code>), \u0438 \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u044f\u043c\u043e\u0439 DNS\u2011\u0437\u0430\u043f\u0440\u043e\u0441.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u0418\u0442\u043e\u0433: \u0447\u0442\u043e \u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u043c\u043d\u0438\u0442\u044c<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>NGINX \u0440\u0435\u0437\u043e\u043b\u0432\u0438\u0442 DNS \u0441\u0430\u043c, \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435.<\/li>\n\n\n\n<li>\u0411\u0435\u0437\u00a0\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445\u00a0\u2014 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f system resolver (glibc).<\/li>\n\n\n\n<li>\u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0439\u0442\u0435\u00a0<code>resolver<\/code>\u00a0\u2014 \u0432\u0441\u0435\u0433\u0434\u0430, \u0435\u0441\u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u0435 \u0441\u00a0\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438.<\/li>\n\n\n\n<li>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u00a0<code>resolver_timeout<\/code>, \u0447\u0442\u043e\u0431\u044b \u043d\u0435\u00a0\u0437\u0430\u043b\u0438\u043f\u0430\u0442\u044c.<\/li>\n\n\n\n<li><code>valid=5s<\/code>\u00a0\u2014 \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u0441\u0442\u0430\u0440\u0442, \u043d\u043e\u00a0\u043d\u0435\u00a0\u0437\u0430\u0431\u044b\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u00a0\u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u043d\u0430\u00a0DNS.<\/li>\n\n\n\n<li>\u0415\u0441\u043b\u0438 \u0443\u00a0\u0432\u0430\u0441 headless\u2011\u0441\u0435\u0440\u0432\u0438\u0441\u044b \u0438\u043b\u0438\u00a0SRV\u2011\u0437\u0430\u043f\u0438\u0441\u0438\u00a0\u2014 \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0433\u043e\u0440\u043e\u0434\u0438\u0442\u044c \u043a\u043e\u0441\u0442\u044b\u043b\u0438 \u0438\u043b\u0438\u00a0\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u043b\u043e\u0430\u0434\u0435\u0440.<\/li>\n<\/ul>\n\n\n\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0434\u0443\u043c\u0430\u043b\u0438, \u0447\u0442\u043e&nbsp;NGINX \u0441\u0430\u043c \u0447\u0442\u043e\u2011\u0442\u043e \u043f\u043e\u0434&nbsp;\u043a\u0430\u043f\u043e\u0442\u043e\u043c \u00ab\u043f\u043e\u0434\u0442\u044f\u0433\u0438\u0432\u0430\u0435\u0442\u00bb, \u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u0437\u043d\u0430\u0435\u0442\u0435: \u043e\u043d \u0442\u0443\u043f\u043e \u043a\u0435\u0448\u0438\u0440\u0443\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u0431\u043e\u043b\u044c\u0448\u0435. \u0418 \u044d\u0442\u0438\u043c \u043e\u043d \u0438 \u0445\u043e\u0440\u043e\u0448&nbsp;\u2014 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u043e\u0441\u0442\u044c \u0434\u0430\u0451\u0442 \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u0443\u0435\u043c\u043e\u0441\u0442\u044c.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041a\u0430\u043a DNS \u0432\u043e\u043e\u0431\u0449\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 Linux (\u0438 \u043f\u043e\u0447\u0435\u043c\u0443 \u044d\u0442\u043e \u0432\u0430\u0436\u043d\u043e \u0434\u043b\u044f NGINX) \u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043f\u0440\u043e&nbsp;proxy_pass&nbsp;\u0432&nbsp;NGINX, \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c,&nbsp;\u0447\u0435\u0440\u0435\u0437 \u043a\u0430\u043a\u043e\u0439 \u0438\u043c\u0435\u043d\u043d\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0440\u0435\u0437\u043e\u043b\u0432\u044f\u0442\u0441\u044f \u0434\u043e\u043c\u0435\u043d\u043d\u044b\u0435 \u0438\u043c\u0435\u043d\u0430, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e&nbsp;\u043e\u0442&nbsp;\u044d\u0442\u043e\u0433\u043e \u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u043a\u0435\u0448\u0438, \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u0440\u0438&nbsp;\u0441\u0431\u043e\u044f\u0445, \u0440\u0435\u0430\u043a\u0446\u0438\u044f \u043d\u0430&nbsp;\u0441\u043c\u0435\u043d\u0443 IP \u0438 \u0432\u043e\u043e\u0431\u0449\u0435 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1656,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[402,51,156],"class_list":["post-1655","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-likbez","tag-dns","tag-linux","tag-nginx","entry-card--landscape"],"_links":{"self":[{"href":"https:\/\/olvas.dev\/index.php?rest_route=\/wp\/v2\/posts\/1655","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/olvas.dev\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/olvas.dev\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/olvas.dev\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/olvas.dev\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1655"}],"version-history":[{"count":1,"href":"https:\/\/olvas.dev\/index.php?rest_route=\/wp\/v2\/posts\/1655\/revisions"}],"predecessor-version":[{"id":1657,"href":"https:\/\/olvas.dev\/index.php?rest_route=\/wp\/v2\/posts\/1655\/revisions\/1657"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/olvas.dev\/index.php?rest_route=\/wp\/v2\/media\/1656"}],"wp:attachment":[{"href":"https:\/\/olvas.dev\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1655"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/olvas.dev\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1655"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/olvas.dev\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1655"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}