减少 DNS 查找时间,加快页面访问速度
站内热度 全站第 2,612
2.6万 次浏览
DNS 预解析
- 前端优化
- 通过meta信息来告知浏览器,页面要做DNS预解析
<meta http-equiv="x-dns-prefetch-control" content="on" /> - 使用link标签来强制对DNS做预解析
<link rel="dns-prefetch" href="https://blog.upx8.com/" /> Nnginx 反向代理动态解析DNS
- 使用 resolver 和 resolver_timeout 参数定时检测 DNS 的变化,自动更新 DNS 对应的 IP 列表。
resolver 223.5.5.5 valid=30s;
resolver_timeout 10
location / {
……
}
- 每隔 5s 使用 IP 为 223.5.5.5 的 DNS 服务器重新解析 blog.upx8.com 对应的 IP,并将 223.5.5.5 的查询超时时间设置为 1s
- 将解析的域名 blog.upx8.com 存储到一个变量中
upstream upx8 {
server 192.168.10.15:8080;
}
or
upstream upx8 {
server blog.upx8.com:8080;
}upstream upx8 {
server 192.168.10.15:8080;
}
resolver 223.5.5.5 valid=5s;
resolver_timeout 1s;
location / {
proxy_pass http://upx8;
} 相关文档
评论与补充0
有问题或想补充的,写在下面 · 选中正文文字再点「报告错误」会自动引用还没有评论。有疑问、补充,或者发现错字,都可以写在下面。