一次HTTP请求完整过程之域名解析
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">在面试过程总会被问到“HTTP协议<span style="color: black;">怎样</span>工作?“,”一次完整的http请求是经历什么过程“...... 确实此题能衡量程序员的功底,<span style="color: black;">倘若</span>你回答非常完整,说明你对网络请求过程是非常<span style="color: black;">认识</span>的,对大流量和大并发场景你就很清楚<span style="color: black;">怎样</span>进行优化,本篇<span style="color: black;">文案</span>从输入URL到浏览器<span style="color: black;">表示</span>页面<span style="color: black;">出现</span>了什么这视角大体<span style="color: black;">认识</span>一下,当你在浏览器<span style="color: black;">位置</span>栏输入网址后浏览器是怎么把<span style="color: black;">最后</span>的页面呈现出来的呢?这个过程从程序员理解的<span style="color: black;">方向</span><span style="color: black;">能够</span>分为以下几个<span style="color: black;">过程</span>:</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">我先给<span style="color: black;">大众</span><span style="color: black;">瞧瞧</span>整体的请求过程,为能更好地让读者明白,作者会分期完整介绍以下过程。</p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/8a89f72455e34408aa7fa6feae902994~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1727804418&x-signature=vMK8X7xTStw%2BmLtW39gJT0uNhXE%3D" style="width: 50%; margin-bottom: 20px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">请求整体过程</p>
</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">域名解析 -> 发起TCP的3次握手 -> <span style="color: black;">创立</span>TCP连接后发起http请求 -> 服务器响应http请求->浏览器得到html代码 -> 浏览器解析html代码<span style="color: black;">同期</span>请求html代码中的资源(如js、css、<span style="color: black;">照片</span>等) -> 浏览器对页面进行渲染呈现给用户。</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/c56b55a5955d452db383313fcc5d2c46~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1727804418&x-signature=mDK2gD4hkuPmBL7rJdVLQCQqxxI%3D" style="width: 50%; margin-bottom: 20px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">获取内容请求</p>
</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">以上过程大致进行分析细节,以方便<span style="color: black;">大众</span>更加<span style="color: black;">仔细</span>地认识整体的过程,<span style="color: black;">然则</span>有些过程<span style="color: black;">无</span>能理解透彻并且过程比较<span style="color: black;">繁杂</span>未能提炼通俗易懂语言给<span style="color: black;">大众</span>分析,<span style="color: black;">不外</span>后续会<span style="color: black;">持续</span>分析给<span style="color: black;">大众</span>的。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">1.域名解析</span></strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">咱们</span>以www.cnblogs.com为例:请问www.cnblogs.com这个域名的IP<span style="color: black;">位置</span>是多少?</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">目的是<span style="color: black;">经过</span>域名<span style="color: black;">位置</span>转化到资源URL的IP<span style="color: black;">位置</span>,对用户<span style="color: black;">运用</span>域名是为了方便记忆,<span style="color: black;">然则</span>为了让计算机理解这个<span style="color: black;">位置</span>还需要把它解析为IP<span style="color: black;">位置</span>,当用户在<span style="color: black;">位置</span>栏输入URL中,浏览器会<span style="color: black;">首要</span>搜索浏览器<span style="color: black;">自己</span>的DNS缓存,先看<span style="color: black;">自己</span>的缓存中<span style="color: black;">是不是</span>存在<span style="color: black;">无</span>过期对应的条目,<span style="color: black;">倘若</span>找到且<span style="color: black;">无</span>过期则停止搜索解析到此结束,<span style="color: black;">倘若</span><span style="color: black;">无</span>浏览器会搜索操作系统的DNS缓存,在操作系统<span style="color: black;">亦</span><span style="color: black;">无</span>找到,<span style="color: black;">那样</span>尝试读hosts文件,<span style="color: black;">瞧瞧</span>里面<span style="color: black;">是不是</span>配置对应域名的IP<span style="color: black;">位置</span>,<span style="color: black;">倘若</span>在hosts文件中<span style="color: black;">亦</span><span style="color: black;">无</span>找到对应的条目,浏览器就会发起一次DNS的系统调用,这过程是<span style="color: black;">经过</span>UDP协议向DNS的53端口发起请求递归迭代请求,这过程有运营商DNS服务<span style="color: black;">供给</span>给<span style="color: black;">咱们</span>,运营商的DNS服务器必须得<span style="color: black;">供给</span>给<span style="color: black;">咱们</span>对应域名的IP<span style="color: black;">位置</span>,先向本地配置的首选DNS服务器发起域名解析请求(<span style="color: black;">通常</span><span style="color: black;">是由于</span>电信运营商<span style="color: black;">供给</span><span style="color: black;">或</span>各大互联网厂商<span style="color: black;">供给</span>的DNS服务器)运营商的DNS服务器<span style="color: black;">首要</span><span style="color: black;">查询</span><span style="color: black;">自己</span>的缓存,找到对应的条目,且<span style="color: black;">无</span>过期,则解析成功。<span style="color: black;">倘若</span><span style="color: black;">无</span>找到对应的条目,则运营商的DNS代浏览器发起迭代DNS解析请求,它<span style="color: black;">首要</span>是会找根域的DNS的IP<span style="color: black;">位置</span>(这台DNS服务器都内置13台根域的DNS的IP<span style="color: black;">位置</span>),找到根域的DNS<span style="color: black;">位置</span>,就会向其发起请求,来一场寻址之旅:</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">运营商DNS:请问www.cnblogs.com这个域名的IP<span style="color: black;">位置</span>是多少呢?</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">根域DNS:你一个顶级域com域的一个域名,我不<span style="color: black;">晓得</span>这个域名的IP<span style="color: black;">位置</span>,<span style="color: black;">然则</span>我<span style="color: black;">晓得</span>com域的IP<span style="color: black;">位置</span>,你去找它去问一问呢?</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">运营商DNS:请问www.cnblogs.com这个域名的IP<span style="color: black;">位置</span>是多少呢?</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">COM域:我不<span style="color: black;">晓得</span>www.cnblogs.com这个域名的IP<span style="color: black;">位置</span>,<span style="color: black;">然则</span>我<span style="color: black;">晓得</span>cnblogs.com这个域的DNS<span style="color: black;">位置</span>,你去找它去去问一问呢?</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">cnblogs.com域名的DNS:这个时候cnblogs.com域的DNS服务器一查,诶,果真在我<span style="color: black;">这儿</span>,<span style="color: black;">通常</span><span style="color: black;">便是</span>由域名注册商<span style="color: black;">供给</span>的,像万网,新网等。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">于是就把找到的结果发送给运营商的DNS服务器,这个时候运营商的DNS服务器就拿到了域名对应的IP<span style="color: black;">位置</span>,并返回给操作系统内核,内核又把结果返回给浏览器,<span style="color: black;">最终</span>浏览器拿到了。</span></p>
<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/9f6322796f67409487e383ad5e351e39~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1727804418&x-signature=tsa0q8M2V2UWSIILuDWd6UJXexI%3D" style="width: 50%; margin-bottom: 20px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">域名解析流程</p>
</div>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">备注:</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">浏览器:<span style="color: black;">能够</span><span style="color: black;">运用</span> chrome://net-internals/#dns 来进行查看</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">操作系统:Mac的dns缓存<span style="color: black;">查找</span> nslookup www.baidu.com</span></p>
论坛的成果是显著的,但我们不能因为成绩而沾沾自喜。 “沙发”(SF,第一个回帖的人)
页:
[1]