HTTP those things

Source: Internet
Author: User
Tags install homebrew domain name server

1. Browser Behavior and HTTP protocol

Browser and server interaction process

After entering the URL in the browser enter:

The browser will first check if the network is through, if it will get the IP address of the URL on the DNS server, and then send an HTTP request, the server receives the request and processes (three handshake), returns the HTML corresponding to the browser processing HTML pages and resources.

First, the client and the server establish a connection (TCP connection). As soon as you click on a hyperlink, the HTTP work begins

Then, after the connection is established, the client sends a request to the server (HTTP request) in the form of a Uniform Resource Identifier (URL), protocol version number, followed by MIME information, including request modifiers, client information, and possible content.

Then, after the server receives the request, it gives the corresponding response information in the form of a status line, including the protocol version number of the information, a successful or incorrect code, followed by MIME information including server information, entity information, and possible content.

Finally, the information returned by the client receiving server is displayed on the user's display by the browser, and then the client disconnects from the server.

2. Who is the DNS maintenance?

DNS is the domain Name System, which is used to convert the domain name to IP

operator maintenance, company maintenance, state-level national maintenance

Top-level domain baidu.com, level two domain name www.baidu.com

Domain Name resource record, domain name server, role, storage resource record and help domain name resolution, domain name resolution

DNS pollution, wall

3. The business is all true, and any one of them fails, and the operation is a transaction.

4. Ios/osi Protocol, Fact Protocol (TCP/IP protocol stack)

TCP is the underlying protocol for HTTP

Application layer, to provide users with the various services required, such as HTTP,FTP,DNS,SMTP, HTTPS more than two TLS and SSL,HTTP2

The transport layer provides an end-to-end communication function for the application layer entities, guaranteeing the sequential transmission and data integrity of the packets. There are two protocols, TCP (end-to-end, pair-one) and UDP (unsecured, transmission integrity not guaranteed, broadcast)

Network layer, mainly to solve the host-to-host communication problems. IP protocol is the most important protocol of Internet layer

Network interface layer, responsible for monitoring the exchange of data between the host and the network

Routers and gateways function Similarly, and routers can set up DNS.

Gateway, restricting network traffic, NIC

5.

Currently the application version HTTP1.1,HTTP2, but not much.

HTTP default port number is 80

HTTPS default port number is 443,https more than HTTP TLS and SSL (link encryption)

6. Requests and Responses

Request headers

  1. accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
  2. Accept-encoding:gzip, deflate, BR
  3. accept-language:zh-cn,zh;q=0.9,en;q=0.8
  4. Cache-control:no-cache
  5. Connection:keep-alive
  6. cookie:baiduid=ca8f324c0f0b6a13b58411f81594f697:fg=1; bidupsid=ca8f324c0f0b6a13b58411f81594f697; pstm=1519610279; bduss= Kl5owljsdzudxroq2j-ee56snpjluryemvudjdtcurku3fkafa0rk5sufq5n3bhqvfbqufbjcqaaaaaaaaaaaeaaaciq3qpodcwmje4bgkaaaaaaaaaaaaaaa Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaannqk1rtapnar; h_ps_pssid=1453_26081_21091; bdorz=b490b5ebf6f3cd402e515d22bcda1598; Bd_ck_sam=1; Psino=1; H_PS_645EC=A97AVBAZZULV8OATZFKXZSV1X2%2BNNRSOQQNCTJ0X3DAZ%2BE9BRUM9MF%2FYFKPYDJSGIDW9; bd_home=1; bd_upn=123253; sug=3; sugstore=1; origin=2; Bdime=0
  7. Host:www.baidu.com
  8. Pragma:no-cache
  9. referer:https://www.baidu.com/
  10. Upgrade-insecure-requests:1
  11. user-agent:mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) applewebkit/537.36 (khtml, like Gecko) chrome/65.0.3325.181 safari/537.36

Response header

    1. accept-ranges: bytes
    2. age: 1548156
    3. Cache-control:  max-age=2592000 //above cache-related
    4. connection: keep-alive
    5. content-encoding: gzip
    6. content-type: text/css
    7. Date: mon, APR 2018 07:17:25 gmt   //server time
    8. ET ag: w/"581AFB4E-60B1"                    //client-side cache
    9. Expires:  sat, APR 2018 09:14:49 GMT
    10. last-modified: thu, 08:54:38 gmt   //Customer Cache  
    11. ohc-response-time: 1 0 0 0 0 0
    12. server: bfe/1.0.8.13-sslpool-patch     /server
    13. set-cookie:bdsvrtm=194; path=/
    14. set-cookie: h_ps_pssid=1453_26081_21091; path=/; domain=. Baidu.com
    15. strict-transport-security: max-age=172800
    16. transfer-encoding: chunked
    17. vary: accept-encoding

7. Request method

Get, request to get the resource identified by Request-uri

Post, append new data to the resource identified by Request-uri//request-uri refers to the request path.

Head, requesting a response message header for the resource identified by Request-uri, which only gets the response header information

PUT,

DELETE

TRACE, primarily for testing or diagnostics

CONNECT, reserved for future use

Options, request the performance of the query server, or query for resource-related choices and requirements

8. Status code for HTTP

1XX: Prompt message indicating that the request has been received, continue processing

2XX: Successful, indicates that the request has been successfully received, understood, accepted

3XX: Redirect to complete the request must be further done

4XX: Client error, request syntax error or request not implemented

5XX: Server-side error, server failed to implement legitimate request

9. Cookies and Session

Cookies can be set on the client or server side

The session is only available on the server side, with a unique value of SessionID to differentiate each user.

Server is based on the session to generate the client's cookie, as the server to identify the user ID, to achieve user login

Identity tokens are placed on the request header to prevent cross-site attacks

10. Caching mechanisms

Advantages, improve efficiency, reduce consumption

One. Link security for HTTP

Encrypt important data

Signing non-critical data

HTTP2.

Transfer in binary format for more efficient and compact use

Lower overhead for header compression

Multiplexing, a network connection implementation for parallel requests

Server proactive push to reduce latency of requests

HTTP and Reverse Proxy

Tcpdump grabbed the bag

What is a proxy, what is a forward proxy, and what is a reverse proxy

Agent is not to do their own, to find other agents themselves

Agent has the role of caching, security issues, sensitive data access issues, equivalent to foreign purchasing, the main function is to limit and speed up (cache)

box means LAN, or computer room, export IP has one, can also do load balancing

The nature of the agent is the same, the request is made a forwarding, the implementation of different

Purpose of the reverse proxy

Encryption and SSL acceleration, load balancing, cache static content, compression, deceleration uploads, security, extranet publishing

Reverse proxy Server

Nginx

Installing Nginx

1. Mac this direct execution
Brew Install Homebrew/nginx/openresty, refer to Http://openresty.org/cn/installation.html

2. The MAC has its own python, and the 2.7 series is available. Install Pip, execute sudo easy_install pip

3. After the installation is complete, modify the server. Open it
/usr/local/etc/openresty/nginx.conf, copy the following code into the file

server {
Listen 6060;
server_name beidou.com;

Location/{
Index index.html index.htm;
Root/users/admin/halley/src/privatesource/front;
Try_files $uri $uri//index.html;
}

Location ^~/api/{
Proxy_set_header Host $host;
Proxy_set_header Proxy-client-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
Client_body_buffer_size 128k;
Proxy_pass http://127.0.0.1:8008/;
}
}
Change the root address to your own directory.

Nginx's Reverse proxy

Within the HTTP module

HTTP {

Upstream web_crm{

Server 127.0.0.1:8080

}

server{

location/crm/{

Proxy_pass http://web_crm/crm/;

Proxy_redirect off;

Proxy_set_header Host $host;

Proxy_http_version 1.1;

Proxy_set_header Upgrade $http _upgrade; Prevent Nginx servers from overwriting clients ' IP and other information

Proxy_set_header Connection ' upgrade ';

Proxy_cache_bypass $http _upgrade;

Proxy_set_header X-real-ip $remote _addr;

Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for

}

}

}

14. Optimization for requests

Front-end performance impact factors, network, DOM processing, browser rendering

W3cprocessing Module

Navigationstart stage, the request begins to be timed,

Redirectstart phase, for cache redirection, local redirection, first check for cache policy, or use local cache

Unloadstart stage, if the local cache has the original things, first unload, and then request

Unloadend

Redirectend stage,

Fetchstart stage, if there is a local cache, then this stage is to get the cache locally

Fetchend stage, if the cache satisfies the requirements, do not network, the request is complete, if not satisfied, then proceed the following steps

Domainlookupstart stage, the address of the Dns,dns server is built into the local computer, if it is a dynamic IP, it is dynamically assigned by DHCP, usually set on the router

Domainlookupend stage,

Connectstart phase, TCP connection starts

(Secureconnectionstart) If it's an HTTPS connection, there's this step.

Connectend phase, TCP connection succeeded

Requeststart stage,

Responsestart Stage

Responseend Stage

Domloading stage, processing

Dominteractive stage, memory handles DOM document markup, Dom turns into tree structure

Domcontentloaded stage,

Domcomplete stage, DOM processing complete

Loadeventstart stage, onload event trigger, browser starts rendering DOM structure

Loadeventend Stage

Three-time TCP handshake and four waves

Data transmission and data reception

The transport layer is the TCP protocol, and the network layer is the IP protocol

Data transmission and parsing process in computers

The composition of the TCP packet and can be subcontracting

TRACEROUTE www.baidu.com Tracking Router

Why three times handshake, confirm back and forth, then establish connection

First client: Ah, this is not Xiao Ming, the second server side: Yes, this is not Xiao Li, the third client: long time no see ah, to chat.

Four waves, goodbye, first time client: I have something, or I go first? Second server side: Ah, you have something to do, third server-side: You have something, you have to be busy, I have no business, the fourth time the client: Then I will go first.

The network is disconnected is the client retries, server-side timeout

The unfinished thing is decided by the upper level agreement.

CDN Concept

Load balancing, bottlenecks, cross-network, network links

CDN is a distribution strategy, integrated solution, mirror server, synchronization data, network link optimization, purpose, speed up

17. Caching Mechanisms

Benefits of Caching:

Reduce response Latency

Reduce network bandwidth consumption

Network is I/O overhead, and I/O related are overhead, server processing pressure and processing speed

Browser Request for the first time

Request again

The cached configuration, which needs to be configured on the server, is typically built-in, and is generally not rewritten

HTTP those things

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.