Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to enable http2 support in Nginx/Openresty

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to enable http2 support in Nginx/Openresty, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!

HTTP/2 is derived from SPDY/2.

The SPDY series of protocols was developed by Google and made public in 2009. Its design goal is to reduce page loading time by 50%. At present, many famous Internet companies, such as Baidu, Taobao and UPYUN, have adopted SPDY series protocols in their websites or APP (the latest version is SPDY/3.1), because its performance improvement is obvious. Mainstream browsers (Google, Firefox, Opera) have long supported SPDY, which has become an industry standard, and HTTP Working-Group finally decided to develop HTTP/2 based on SPDY/2.

However, there are still differences between HTTP/2 and SPDY, mainly in the following two points:

HTTP/2 supports plaintext HTTP transmission, while SPDY enforces the use of HTTPS

The compression algorithm for HTTP/2 headers uses HPACK instead of DEFLATE, which is adopted by SPDY

Advantages of HTTP/2

Compared with HTTP/1.x,HTTP/2 in the underlying transmission has made a lot of changes and optimization:

HTTP/2 transmits data in binary format instead of HTTP/1.x text format. Binary format brings more advantages and possibilities in protocol parsing and optimization expansion.

HTTP/2 uses HPACK to compress and transmit the message header, which can save the network traffic occupied by the message header. And HTTP/1.x

Each request will carry a lot of redundant header information, wasting a lot of bandwidth resources. Head compression can solve this problem very well. Multiplexing, to put it bluntly, is that all requests are done concurrently through a TCP connection. Although HTTP/1.x can also make concurrent requests through pipeline, the response between multiple requests will be blocked, so pipeline has not been widely used so far, and HTTP/2 has achieved real concurrent requests. At the same time, the flow also supports priority and flow control.

Server Push: the server can push resources to the client more quickly. For example, the server can actively push JS and CSS files to the client without requiring the client to parse the HTML and then send these requests. When the client needs it, it is already on the client side. HTTP/2 is mainly a complete reconfiguration of HTTP/1.x on the underlying transport mechanism, and HTTP/2 is basically compatible with the semantics of HTTP/1.x (please click here for detailed compatibility instructions). Content-Type is still Content-Type, except that it is no longer a text transfer.

Openresty/Nginx does not support http2 by default, and the http2 module needs to be compiled into the application.

Let's take Openresty as an example to introduce the compilation steps.

Download openssl-1.0.2l

Wget https://www.openssl.org/source/openssl-1.0.2l.tar.gz tar-zxvf openssl-1.0.2l.tar.gz

Generate compilation information

. / configure-with-http_v2_module-with-openssl=/openssl-1.0.2l

Perform compilation

Make make install

If no error is reported, the compilation is successful.

The following is to modify the nginx configuration file, focusing on enabling http2. 443 ssl where it is enabled. As follows:

Server {listen 443 ssl http2;.}

Execute reload and open the web page to verify that it is successful.

If you find it troublesome to compile, you can use the openresty that I have compiled:

Vikings/openresty:http2 above is all the content of the article "how to enable http2 support in Nginx/Openresty". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report