第十一周-day45-HTTP协议

作者: Linux丶晨星 | 来源:发表于2019-06-03 13:11 被阅读66次
    第十一周-day45-HTTP协议.png

    1.http是什么

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

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

    2.DNS解析流程详解


    DNS域名解析过程


    windows 本地hosts文件:

    域名结构(层次)

    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记录
        邮件使用
    

    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  存活时间(缓存时间)
    

    HTTP请求报文与响应过程:

    image.png

    客户端请求:

    服务端响应:

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

    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 
    ....
    

    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.png

    作业:

    研究tcpdump抓包(linux)
    根据ip抓包
    根据端口抓包
    根据协议抓包

    用户浏览器输入网址进入的过程发生了什么?
    DNS解析
    TCP
    http

    相关文章

      网友评论

        本文标题:第十一周-day45-HTTP协议

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