Why HTTP2?

Recently our company's official website has been upgraded from the original http1.1 to http2, and we are still a front-end development of http2 ignorant, but I do not know why this changed, therefore complement the knowledge of at http2.

http1.1 compared to http1.0 What are the advantages?

  1. Caching
    is mainly used in the header of the If-Modified-Since In HTTP1.0, Expires determination of cache do the standard,
    the HTTP1.1 it introduces more cache control strategy e.g. Entity tag, If-Unmodified-Since , If -Match, If-None-Match, and more choice of head control cache caching policy.

  2. Bandwidth optimization and network connections using
    HTTP1.0, there are some waste bandwidth phenomena, such as the client needs only a part of an object, and the server puts the whole object gets here and does not support the HTTP functionality, HTTP1 .1 the range request header header introduced, which allows only a portion of the requested resource, i.e., a return code 206 (Partial Content), thus enabling easy selection developer in order to take advantage of a free bandwidth and connectivity.

  3. Error notification management
    new in HTTP1.1 24 in the error status response codes, such as 409 (Conflict) represents the current state of the resource request and resource conflicts; 410 (Gone) represents a resource on the server permanently deleted.

  4. Host header processing
    believed to bind each server a unique IP address in HTTP1.0, therefore, the request URL in the message did not get through the host name (hostname). But with the development of virtual mainframe technology, there can be multiple virtual hosts (Multi-homed Web Servers) on a single physical server, and they share a single IP address.
    HTTP1.1 request and response messages should support Host header field, and the request message if no Host header field report an error (400 Bad Request).

  5. Long connection
    HTTP 1.1 support long connections (PersistentConnection) and request pipeline (Pipelining) process, in a TCP connection may transmit a plurality of HTTP requests and responses, reducing and closing the connection establishment delay and consumption, the default HTTP1.1 open connection: keep-alive, to make up for the shortcomings of HTTP1.0 each request to create a connection to a certain extent.

http2 compared to http1.1 What are the advantages?

  1. Binary framing
    HTTP / 2 binary transmission format of data, rather than HTTP 1.x text format, binary protocol more efficient to resolve. In HTTP / 2, all traffic over a single connection is made at the same domain name, the connection bi-directional data stream may carry any number. Each data stream is transmitted in the form of message, and the message in turn by one or more frames. Can be sent out of order between a plurality of frames, according to the stream identifier of the frame header may be re-assembled.
  2. Multiplexing
    the multiplexed to replace the original sequence and blocking mechanisms. All requests are concurrent connections is done through a TCP. HTTP 1.x, if you want multiple concurrent requests, you must use multiple TCP connection, and the browser in order to control the resources, there will be 6-8 TCP connections request limit for a single domain name
  3. Server push
    server can take the initiative to push HTML pages when sending other resources, without waiting for the browser parses it into place, and then initiate a request response.
  4. Header compression
    HTTP 1.1 request size getting bigger, sometimes even greater than the initial TCP window size, because they are waiting for the response with an ACK can continue to be sent back later. HTTP / 2 message header compression using HPACK transfer (specifically for the compression format http / 2 head design), it is possible to save traffic message header occupied network. The HTTP / 1.x every request, will carry large amounts of redundant headers, wasted a lot of bandwidth.

HTTP2.0 long connection multiplexing and HTTP1.X in multiplexing What is the difference?

  1. HTTP / 1.0 a request - response, a connection is established, run off; every request to establish a connection;
  2. HTTP / 1.1 Pipeling solution is, the request is queued serial number of a single-threaded process, subsequent requests return the requested waiting in front to get the opportunity to perform, if there is a timeout request, subsequent requests can only be blocked, no way, It is commonly known as head of line blocking;
  3. HTTP / 2 a plurality of requests can be performed simultaneously in parallel on a connection. Request a time-consuming task seriously, it will not affect the normal execution of other connections;

Configuring the nginx http2.0

Although HTTP2.0 can actually support non-HTTPS, but now the mainstream browsers like chrome, firefox still represent only support HTTP2.0 protocol is based on TLS deployments, so in order to upgrade to first upgrade HTTP2.0 or HTTPS as well.
Configuring the https basis to http2 is very simple,
open HTTP / 2 requires Nginx 1.9.5 or later, and requires version 1.0.2 OpenSSL more on Nginx.
View openssl version

openss version
OpenSSL 1.0.2k-fips  26 Jan 2017

Nginx modified configuration
after the configuration server listen in paragraph http2 to increase.

server{
    listen  443 ssl http2;
    ···
}

Restart nginx nginx -s reload
this point you can see whether a http2 is in effect in the browser

Reference Documents

  1. Difference HTTP1.0, HTTP1.1 and the HTTP2.0
  2. Configuring HTTP / 2 Concise Guide on Nginx

Guess you like

Origin www.cnblogs.com/jesse131/p/11529931.html