美文网首页
45-HTTP协议

45-HTTP协议

作者: 杨丶子 | 来源:发表于2019-06-05 15:00 被阅读0次

1.http是什么

用户浏览器输入网址进入的过程发生了什么
用户访问网站的流程

DNS解析过程,     域名对应的ip地址          
TCP/ip 三次握手, 与服务器建立链接
HTTP请求报文,    用户向服务器要东西(图片 页面)
HTTP响应报文,    把你要的内容给你
TCP/ip 四次挥手, 与服务器断开连接

image

2.DNS解析流程详解

image image

DNS域名解析过程

image image

windows 本地hosts文件:

image

域名结构(层次)

www.baidu.com.  (最后的点)
[d:\~]$ ipconfig /displaydns
    查看DNS缓存
[d:\~]$ ipconfig /display
    释放DNS缓存
[d:\~]$ ipconfig /flushdns
    清空DNS缓存

3.dig 命令使用方法

https://www.imooc.com/article/26971?block_id=tuijian_wz
dig命令主要用来从 DNS 域名服务器查询主机地址信息
yum provides dig
查询安装包
yum install -y bind-utils
安装dig bind-utils

dig www.baidu.com www.jd.com

DNS记录的类型

dig +trace www.baidu.com

记录1个对应关系
A记录
    域名 ip地址记录
CNAME记录
    别名记录
MX记录
    邮件使用

image

nslookup 属于dig软件包

[10:25 root@web01 ~]# rpm -qf `which nslookup`
bind-utils-9.9.4-73.el7_6.x86_64
[10:27 root@web01 ~]# nslookup
> www.baidu.com
Server:     10.0.0.254
Address:    10.0.0.254#53

Non-authoritative answer:
www.baidu.com   canonical name = www.a.shifen.com.
Name:   www.a.shifen.com
Address: 39.156.66.14
Name:   www.a.shifen.com
Address: 39.156.66.18
> 

host 属于dig软件包

[10:28 root@web01 ~]# host www.baidu.com
www.baidu.com is an alias for www.a.shifen.com.
www.a.shifen.com has address 39.156.66.18
www.a.shifen.com has address 39.156.66.14

搭建网站流程

云服务器
    搭建LNMP环境部署 wordpress
购买域名
    备案(网站基本性信息 个人信息 提交给信息管理局)
配置DNS解析(记录)
    记录类型
    主机记录
    记录值
    TTL  存活时间(缓存时间)

image image

HTTP请求报文与响应过程:

image
image image

客户端请求:

image

服务端响应:

image

客户端请求与服务端响应的过程:

curl -v www.baicu.com

[11:31 root@web01 ~]# curl -v www.baidu.com/index.html
* About to connect() to www.baidu.com port 80 (#0)   \\DNS解析
*   Trying 39.156.66.14...
* Connected to www.baidu.com (39.156.66.14) port 80 (#0)   \\Tcp三次握手
> GET /index.html HTTP/1.1    \\http请求报文 ,请求起始行
> User-Agent: curl/7.29.0     \\用户的浏览器
> Host: www.baidu.com         \\请求域名
> Accept: */*   
>                           \\空行
< HTTP/1.1 200 OK
< Accept-Ranges: bytes
< Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
< Connection: Keep-Alive
< Content-Length: 2381
< Content-Type: text/html
< Date: Mon, 03 Jun 2019 03:32:03 GMT
< Etag: "588604c8-94d"
< Last-Modified: Mon, 23 Jan 2017 13:27:36 GMT
< Pragma: no-cache
< Server: bfe/1.0.8.18
< Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/
< 
<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type 
content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible 
content=IE=Edge><meta content=always name=referrer><link rel=stylesheet 
type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>
百度一下,你就知道</title></head> <body link=#0000cc> <div id=wrapper> <div 
....

image

wget --debug www.baidu.com

[12:06 root@web01 ~]# wget --debug www.baidu.com
DEBUG output created by Wget 1.14 on linux-gnu.

URI encoding = ‘UTF-8’
Converted file name 'index.html' (UTF-8) -> 'index.html' (UTF-8)
Converted file name 'index.html' (UTF-8) -> 'index.html' (UTF-8)
--2019-06-03 12:07:08--  http://www.baidu.com/
Resolving www.baidu.com (www.baidu.com)... 39.156.66.18, 39.156.66.14
Caching www.baidu.com => 39.156.66.18 39.156.66.14
Connecting to www.baidu.com (www.baidu.com)|39.156.66.18|:80... connected.
Created socket 3.
Releasing 0x000000000138e9a0 (new refcount 1).

---request begin---
GET / HTTP/1.1
User-Agent: Wget/1.14 (linux-gnu)
Accept: */*
Host: www.baidu.com
Connection: Keep-Alive

---request end---
HTTP request sent, awaiting response... 
---response begin---
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Connection: Keep-Alive
Content-Length: 2381
Content-Type: text/html
Date: Mon, 03 Jun 2019 04:07:07 GMT
Etag: "588604c8-94d"
Last-Modified: Mon, 23 Jan 2017 13:27:36 GMT
Pragma: no-cache
Server: bfe/1.0.8.18
Set-Cookie: BDORZ=27315; max-age=86400; domain=.baidu.com; path=/

---response end---
200 OK
cdm: 1 2 3 4 5 6 7 8
Stored cookie baidu.com -1 (ANY) / <permanent> <insecure> [expiry 2019-06-04 12:07:08] BDORZ 27315
Registered socket 3 for persistent reuse.
Length: 2381 (2.3K) [text/html]
Saving to: ‘index.html’

100%[========================================>] 2,381       --.-K/s   in 0s      

2019-06-03 12:07:08 (29.2 MB/s) - ‘index.html’ saved [2381/2381]

※Wireshark抓包

image
image

请求流程

image

响应流程

image

状态码含义:

image image image image image

相关文章

  • 45-HTTP协议

    1.http是什么 用户浏览器输入网址进入的过程发生了什么用户访问网站的流程 image 2.DNS解析流程详解 ...

  • git协议

    git支持的协议 local协议 https协议 ssh协议 git协议 github常用的协议

  • Dubbo服务 上传文件解决方案以及Hessian协议

    协议支持Dubbo支持多种协议,如下所示: Dubbo协议 Hessian协议 HTTP协议 RMI协议 WebS...

  • Procotol 和 Delegate

    目录 Procotol 协议的概念 协议的分类 协议的定义 协议的遵循 协议的方法 协议的属性 Delegate ...

  • 计算机网络题目

    几种协议分别属于哪一层传输层协议:TCP协议、UDP协议应用层协议:FTP、HTTP、SMTP网络层协议:IP协议...

  • ARP协议

    地址解析协议ARP 网络层四大协议:ARP协议,IP协议,ICMP协议,IGMP协议。 ARP(Address R...

  • IP数据报格式

    前言 先回顾一下TCP/IP协议栈 网络层的协议有IP协议、ARP协议、ICMP协议和IGMP协议。其中IP协议是...

  • 名词解析

    网络层:IP协议 : 网络协议ICMP协议: Internet互联网控制报文协议 ->IP协议的附属协议 IP...

  • 如何将Git仓库备份到本地

    git常用的传输协议传输协议.png哑协议:哑协议传输进度不可见;智能协议传输可见。传输速度:智能协议比哑协议传输...

  • NSURLSession学习笔记

    �Http协议-超文本传输协议 Http协议是应用层协议,底层要求的传输协议必须是可靠的传输协议,通常是TCP协议...

网友评论

      本文标题:45-HTTP协议

      本文链接:https://www.haomeiwen.com/subject/lkfsxctx.html