1、描述html
一、nginx配置转发的时候使用的是域名,即便用dns服务方便配置和负载。可是nginx默认会进行缓存,当域名对应的服务出问题的时候就会报错,只有默认的缓存时间到了才会再次进行解析,nginx在resolver后面有个参数valid设置缓存过时时间。并使用set强制解析(又个弊端,就是不会在使用系统的/etc/resolv.conf)可是咱们的服务都是使用的consul管理的,因此不存在这个问题。nginx
二、设置valid时间必定要肯定dns的安全缓存
2、配置安全
参考:http://nginx.org/en/docs/http/ngx_http_core_module.html#resolver服务器
Syntax: resolver address ... [valid=time] [ipv6=on|off]; Default: — Context: http, server, location
Syntax: resolver_timeout time; Default: resolver_timeout 30s; Context: http, server, location
server { listen 80; server_name evk.epget.com; location / { resolver 10.42.3.6 valid=30s; set $kkk "http://activity.service.hq:4072"; proxy_pass $kkk; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; }
3、consul 提供DNSdom
consul服务部署参考个人博客:https://www.cnblogs.com/cuishuai/p/8194345.htmlui
这里不作介绍,注意配置的时候指定dns端口为53,默认端口是8600.设置本身的domain,例如设置为hq,本身定义便可。spa
在nginx服务器上面提供解析能力,在/etc/resolv.conf添加以下信息code
nameserver 10.42.3.6
10.42.3.6是consul的监听地址。server