问题
在内网测试机上测试时发现,nginx解析locathost错误,实际resolver指向内网DNS服务192.168.0.1,抓包发现nginx发起dns查询向192.168.0.1查询失败。并且nginx并没有去读取本地hosts文件。
解决方法
用dnsmasq在本地自建DNS服务,nginx配置 resolver指向127.0.0.1,配置/etc/dnsmasq.conf文件
#/etc/dnsmasq.conf
domain-needed
bogus-priv
cache-size=51200
listen-address=127.0.0.1
#注意此处指向DNS服务,实际还是向内网DNS查询
resolv-file=/etc/resolv.conf
实际上是配置了dnsmasq后除了查询内网DNS,还会默认去读取本地hosts文件来解析localhost
参考:http://www.jb51.net/article/60522.htm