Nginx 1.4.2ã§è©¦ãã¾ããã
ãã¼ã ãµã¼ãã¼ã¯ããã¼ã«ã«ã®unboundãlocal-zone, local-dataã使ã£ã¦ç°¡æã³ã³ãã³ããµã¼ãã¼ã«ãã¦è©¦ãã¾ããã
local-zone: "oreno." static local-data: "api.oreno. 30 IN A 192.0.2.11" # local-data: "api.oreno. 30 IN A 192.0.2.12"
proxy_passã«ãã¹ãåãæ¸ãã¨âåå解決ã¯ä¸åº¦ã ã
ãã®ããã« Nginx ã®è¨å®ãæ¸ããå ´åã
location /api { proxy_pass http://api.oreno:9999; }
- ãapi.orenoãã®åå解決ã¯ãnginxã®èµ·åæã«è¡ããã¾ã
- åå解決ã§ããªãå ´åã¯ãnginxã¯èµ·åãã¾ãã
- åå解決ã§ããå ´åã¯ããã£ã¨ãã®IPã¢ãã¬ã¹ã«reverse proxyãã¾ã
ã¨ããæåã«ãªãã¾ãã
ã¤ã¾ãããã¹ãåã«ç´ã¥ãIPã¢ãã¬ã¹ãDNSçã«å¤æ´ããã¦ããnginxã¯ï¼HUPãåããã¾ã§ã¯ï¼å¤ãIPã¢ãã¬ã¹ã«reverse proxyãç¶ãã¾ãã
å®æçã«åå解決ãããã«ã¯ã©ãããã°ãããï¼
ãã®ããã«ãsetãã£ã¬ã¯ãã£ãã§å¤æ°ã«ãã¹ãåãã»ããããproxy_passã§ã¯ãã®å¤æ°ãåç §ããã°ãå®æçã«ååãå¼ãç´ãã¦ãããããã«ãªãã¾ããããããªæãããã¾ãããå ¬å¼ããã¥ã¡ã³ãã«ããã®æåã¯ã¡ããã¨è¨ããã¦ãã¾ãã
location /api { resolver 127.0.0.1; set $api_backend "api.oreno"; proxy_pass http://$api_backend:9999; }
- http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass
- ä¸ã®æ¹ã®ãA server name, its port and the passed URI can also be specified using variables:ãã®ããã
ãã®æãresolverãã£ã¬ã¯ãã£ãããããã¦æå®ããªãã¨ããno resolver defined to resolve api.orenoãã¨ã¨ã©ã¼ãã°ã«è¨ãããã¯ã©ã¤ã¢ã³ãã«ã¯ 502 Bad Gateway ãè¿ãããã®ã§æ³¨æãã¦ãã ããã
ããã©ã«ãã§ã¯DNSå¿çã®TTLãåãããå度åãåããã«è¡ãã¾ããã
location /api { resolver 127.0.0.1 valid=2s; set $api_backend "api.oreno"; proxy_pass http://$api_backend:9999; }
ã¨ãresolverãã£ã¬ã¯ãã£ãã«validãªãã·ã§ã³ãæå®ãããã¨ã«ãã£ã¦ãTTLã®å¤ã«é¢ãããã2ç§çµéãããã¾ãå度DNSåãåããããããã«ãã§ãã¾ãã
upstreamãã£ã¬ã¯ãã£ãã§serverãç¾ åãã¦ãå ´åã«ãå®æçã«åå解決ãããã«ã¯ï¼
upstream api_upstream { resolver 127.0.0.1; set $api1 "api1.oreno"; server $api1; set $api2 "api2.oreno"; server $api2; } location /api { proxy_pass http://api_upstream:9999; }
ã¨æ¸ãã°ã§ãããã«æãã¾ãããã¡ã§ãããªããªããsetãã£ã¬ã¯ãã£ãã¯upstreamã³ã³ããã¹ãã§ã¯æå®ã§ããªãããã§ãã
upstreamãã£ã¬ã¯ãã£ãã§serverãç¾ åãã¦ãå ´åã«ãå®æçã«åå解決ãããæ¹æ³ã¯ãªãããã«æããã®ã§ããããªã«ãããæ¹æ³ããã£ããæãã¦ããããã¨ããããã§ãï¼ï¼
追è¨
1.5.12以éãªããserverãã£ã¬ã¯ãã£ãã«resolveãã©ã¡ã¼ã¿ãã¤ããã°httpãããã¯ã®resolverã®è¨å®ã®éãã«ååãå¼ãç´ãã¦ãããããã§ãã
http { resolver 127.0.0.1; upstream api_upstream { server api.oreno resolve; } }
ãã£ãã¼ï¼ï¼ï¼ï¼ã¨æã£ã¦è©¦ãã¦ã¿ãã®ã§ãããnginx: [emerg] invalid parameter "resolve" in ...ãã¨æãããããã¨ãããããã¥ã¡ã³ãèªãã ãã
Additionally, the following parameters are available as part of our commercial subscription:
ã¨æ¸ãã¦ããã¾ããï¼ï¼
追è¨ã®è¿½è¨
2024-11-26 ã«ãªãªã¼ã¹ããã 1.27.3 㧠resolve ã使ããããã«ãªãã¾ããã
追è¨2
ã使ãã°ã§ãã¾ãããnginx 1.8.0ã§ç¢ºèªãnginx 1.4.1ã§ã¯ãã«ããã§ãã¾ããã§ããã
ããã§TTLå¾ã«å¼ãç´ãã
http { resolver 127.0.0.1; upstream api_upstream { dynamic_server api.oreno; } }
ããã§TTLã«é¢ä¿ãªã2ç§å¾ã«å¼ãç´ãã¦ããã¾ããï¼
http { resolver 127.0.0.1 valid=2s; upstream api_upstream { dynamic_server api.oreno; } }
追è¨3
- https://www.nginx.com/resources/wiki/modules/
- https://www.nginx.com/resources/wiki/modules/domain_resolve/
ã§ãç´¹ä»ããã¦ãã https://github.com/wdaike/ngx_upstream_jdomain/ ã使ã£ãã»ããããããã§ãã
Nginx 1.14ã§ã¯ã³ã³ãã¤ã«ã§ããªãã£ãã®ã§ fork ã®
https://github.com/mwhipple/ngx_upstream_jdomain ã試ãã¾ããããã£ã¬ã¯ãã£ãã jdomain ãã hostname ã«å¤ãã£ã¦ããç¹ã«æ³¨æãã¦ãã ããã
http { resolver 127.0.0.1 valid=2s; upstream api_upstream { hostname api.oreno; } }
追è¨4
Apacheã ã¨ProxyPassã«disablereuse=Onãã¤ããã°ããã£ã½ãã
ãªãã®ãDNS error (32: Unknown error), query id:XXXXXã
ã¾ã åç¾æ¹æ³ãããããªãã®ã§ãããproxy_passã§å¤æ°åç §ãã¦ããå ´åã«ãã®ã¨ã©ã¼ãåºã¦æ°ç§ãåæ°ç§éreverse proxyã§ããªããªãç¾è±¡ãèµ·ãã¦ãã¾ãã
ãã¡ãä½ãæ å ±ãæã¡ã®æ¹ã¯æãã¦ããã ããã¨ããããã§ãï¼ï¼
ãã¾ã: nginxã®debug log
configureããã¨ãã« --with-debug ããä¸ã§ã
error_log /path/to/file debug;
ã¨ããã¨ãnginxãdebug logãåãããã«ãªãã¾ããresolverã®æåãããã§ç¢ºèªã§ãã¾ãããã ãããªãã®éãåãã®ã§æ³¨æãã¦ãã ããã
ãã¨ãã³ã³ããã¹ãã«ãã£ã¦åããããã°ãéãã®ã§ãserverãhttpã³ã³ããã¹ãã ãã§ãªããä¸çªå¤å´ã®mainã³ã³ããã¹ãã«ãerror_logãã£ã¬ã¯ãã£ããæ¸ããæ¹ãããã§ãã