What's going on behind the scenes in the browser accessing a website?

Source: Internet
Author: User

Title, what goes through the browser to visit a website?

Content from: https://www.cnblogs.com/yangliheng/p/6112955.html

Objective

Come on, go with me. To clean up the HTTP and DNS protocols, whether you're dev or ops these are basic network knowledge that you have to know, as shown in the process of accessing the site, we've divided the user into two parts:

    1. DNS (IP address for resolving domain names)
    2. HTTP (Get the data from the server after getting the IP address)

Based on the two points above, let me discuss in depth what is the DNS and HTTP put.

What is DNS?
The domain Name System, abbreviation: DNS, is a service of the Internet. It is a distributed database that maps domain names and IP addresses to each other, making it easier for people to access the Internet.
DNS uses TCP and UDP port 53. Currently, the limit for each level of domain name length is 63 characters, and the total length of the domain name cannot exceed 253 characters.
DNS principle

As shown above, DNS is actually converting a domain name into an IP (a record) address (although this is only part of it), then how is it converted?

When the user in the browser input http://blog.wangwang.me , how to get the corresponding server IP address it? The steps are as follows:

  1. The browser will find in the local cache whether there is a cache of the current access domain name, if any, return data, or continue the second step, usually the browser will cache the site's data, in order to speed up access;
  2. Check whether the current operating system hosts file is written with IP and domain name corresponding to the relationship, if any, get the IP address, otherwise continue the third step;
  3. The local DNS to obtain the corresponding IP address of the domain name, then the local DNS is actually our switch or router configuration of DNS, usually have two, one Master one auxiliary;
  4. Local DNS will first look at the cache DNS for this record, if not, continue to go down, or return the IP address;
  5. Local DNS will continue to request root server ( . ), the root server has only 13 servers globally, the root server does not have blog.wangwang.me domain name parsing, but the root has a . Me domain name parsing, then the root will continue to initiate the request, Of course, this is done only in forwarding mode.
  6. Root server request . Me Server There is no parsing of blog.wangwang.me domain name, the. Me server server does not have corresponding parsing, but I have wangwang.me domain name parsing , and then the . Me server continues to initiate the request;
  7. . Me DNS server asked wangwang.meDNS server has no blog.wangwang.me Domain name resolution,wangwang.meDNS Server said I have blog.wangwang.me domain name analysis;
  8. wangwang.me The DNS server returns the IP address of the blog.wangwang.me domain name resolution to the. MeDNS server;
  9. . Me The DNS server returns records to the root server;
  10. The root server returns records to the local DNS server
  11. The Local DNS server will also present the records to the DNS cache server, and return the records to the browser again;
  12. When the browser obtains the corresponding IP address, it initiates an HTTP request to the blog.wangwang.me corresponding server;
  13. blog.wangwang.me Server after the processing of some columns, and finally return the data to the browser, and finally on the page display;
    • The following is the non-enabled forwarding mode workflow
    1. The Local DNS Server initiates a request to the root server to ask if there are any blog.ansheng.me domain name parsing records;
    2. Root Server said I do not have blog.ansheng.me domain name parsing record, but I have a . me parsing record, and return the parse record of . Me to Local DNS server;
    3. The Local DNS server gets the. Me server IP after initiating the request Q: Do you have a blog.ansheng.me* domain name parsing record;
    4. The . me server said I did not, but I have the ansheng.me domain name of the parsing record, and the IP address returned to the Local DNS server;
    5. The Local DNS Server obtains the ansheng.me server IP and then initiates the request asking: Do you have the parsing record of the blog.ansheng.me domain name;
    6. ansheng.me 's server said I had a parse record of the blog.ansheng.me domain name and returned the corresponding parsed records to the Local DNS Server

Regardless of the forwarding mode or root hints, the result is returned to the local DNS server, which is then returned to the client.

From the browser to the local DNS server is a recursive query, and the DNS server is the interactive query is the iterative query

digThe parsing process can be clearly seen through the command:

1[Email protected] ~]# dig +Trace Blog.ansheng.me2  3; <<>> DiG9.8.2rc1-redhat-9.8.2-0.47. Rc1.el6_8.1<<>> +Trace Blog.ansheng.me4;;GlobalOptions: +cmd5.4695In NS a.root-servers.net.6.4695In NS b.root-servers.net.7.4695In NS c.root-servers.net.8.4695In NS d.root-servers.net.9.4695In NS e.root-servers.net.Ten.4695In NS f.root-servers.net. One.4695In NS g.root-servers.net. A.4695In NS h.root-servers.net. -.4695In NS i.root-servers.net. -.4695In NS j.root-servers.net. the.4695In NS k.root-servers.net. -.4695In NS l.root-servers.net. -.4695In NS m.root-servers.net. -;; Received228bytes from 8.8.8.8# -(8.8.8.8)inch  +Ms +   -Me.172800In NS ns.nic.me. +Me.172800In NS a2.me.afilias-Nst.info. AMe.172800In NS d0.cctld.afilias-nst.org. atMe.172800In NS ns2.nic.me. -Me.172800In NS b2.me.afilias-nst.org. -Me.172800In NS c0.cctld.afilias-Nst.info. -Me.172800In NS a0.cctld.afilias-Nst.info. -Me.172800In NS b0.cctld.afilias-nst.org. -;; Received491bytes from 202.12.27.33# -(202.12.27.33)inch 678Ms in   -Ansheng.me.86400In NS dns10.hichina.com. toAnsheng.me.86400In NS dns9.hichina.com. +;; Received thebytes from 199.254.61.1# -(199.254.61.1)inch  theMs -   theBlog.ansheng.me. -In A104.224.139.81 *;; Received thebytes from 140.205.228.13# -(140.205.228.13)inch 182Ms

What is HTTP?
Hypertext Transfer Protocol (English: hypertext Transfer Protocol, abbreviation: HTTP) is one of the most widely used network protocols on the Internet. HTTP was originally designed to provide a way to publish and receive HTML pages. Resources requested through HTTP or HTTPS protocols are identified by a Uniform Resource identifier (Uniform Resource Identifiers,uri).
HTTP messages

There are two types of HTTP messages:

    1. Request message, client-initiated request to the server
    2. Response message (Response message), the server responds to the client's request
    • Requesting message (Request message)
Message Information
Request Line Tell the server I use the HTTP1.1 protocol to get (get) /index.html this resource
Request Header The request header is composed of Key/value, the function of the request header is that the client tells the server about the request.
Blank Line Tell the server there's no information for the request header.
Request message body Segment The main part contains the data to be sent to the server

    • Response message (Response message)
Message Information
Start line Protocol and version number, number status code, status information
Response Head Key/value composition
Blank Line Tell the server there's no message for the response header.
Request message body Segment A string (for example: HTML)

In the above we can see that the request header points

1 # Request Line2GET https://www.ansheng.me/HTTP/1.13 # Request Header4 Host:www.ansheng.me5connection:keep-Alive6pragma:no-Cache7cache-control:no-Cache8Upgrade-insecure-requests:19user-agent:mozilla/5.0(Windows NT10.0; Win64; x64) applewebkit/537.36(khtml, like Gecko) chrome/55.0.2868.3safari/537.36Tenaccept:text/html,application/xhtml+xml,application/xml;q=0.9, image/webp,*/*; q=0.8 One Accept-encoding:gzip, deflate, SDCH, BR A accept-language:zh-cn,zh;q=0.8 - Cookie: _gat=1; _ga=ga1.2.1463852464.1476801026 - # because it is a get method, there is no request message body

Response header:

1 # start line2http/1.1  $OK3 # response Header4 Server:nginx5Date:tue, -Oct .  -: A: *GMT6content-type:text/html; charset=utf-87Last-modified:sun, GenevaOct .  to:Wuyi: -GMT8transfer-encoding:chunked9connection:keep-AliveTenvary:accept-Encoding Oneetag:w/"57F0A055-9FC" AExpires:fri, +Oct .  -: A: *GMT -Cache-control:max-age=259200 -content-Encoding:gzip the # blank Line -   - # Request message body segment, in the browser is not garbled - 2da +V N0W F S M, R HH Q L?5L v?? } y2 $ y s [{, _s/. W? vi{ -Q8 +   AFiddler:rawdisplay truncated at -Characters. Right-click to disable truncation. ***

What's going on behind the scenes in the browser accessing a website?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.