为什么DNS查找会在本地花费大量时间?

时间:2017-11-17 09:31:13

标签: nginx dns localhost

为了拥有一个相当的"类似的"在本地和生产方法中,我设置了一个NGINX,将请求代理到localhost:port。在制作中,它会从subdomain.example.com重定向到localhost:port。在本地,它从subdomain.example.local重定向到localhost:port,我根据以下内容更改了主机:

127.0.0.1 sub1.example.local
127.0.0.1 sub2.example.local
.
.
.

当我测试我的构建前端时,DNS查找需要花费大量时间(10秒以上),我想知道为什么。

chrome network screen

想法?

2 个答案:

答案 0 :(得分:0)

您可能在/etc/resolv.conf中有两个以上的名称服务器条目,并且在测试时使用的是第一个名称服务器,但可能是您的记录未在该服务器中找到,因此使用第二个名称服务器。

要加快此过程,可以在/etc/resolv.conf

中添加
options timeout:1 attempts:2

来自man

timeout:n     sets the  initial amount of time the resolver
              will wait for a response  from a remote name
              server before retrying the query  via a differ-
              ent name  server. 

attempts:n    sets the  number of times the resolver will send
              a query to each of its name servers before giv-
              ing up and returning an error to  the calling
              application.

另一种加速更多功能的方法是将您的域名添加到/etc/hosts,例如:

1.2.3.4    www.example.com
127.0.0.1  foo.local bar.local sub1.example.local

答案 1 :(得分:0)

问题解决了,并且与chrome优化模块(~DNS预取)有关:

如果您遇到此问题,请转到:

  • 设置>>提前>>隐私和安全
  • 禁用“使用预测服务更快地加载页面”
相关问题