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 Nginx merges request connections and accelerates website access

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

Share

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

This article will explain in detail how Nginx merges request connections and speeds up website access. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

A little knowledge

When we browse the web, there is an important factor affecting the browsing speed, which is the number of concurrency of browsers. In simple and popular terms, the number of concurrency is the number of people working at the same time when browsing a web page.

Of course, the limit on the number of concurrent requests for browsers is for the same domain name, and there is a limit on the number of requests under the same domain name at the same time, and requests exceeding the limit will be blocked.

First, let's take a look at the number of concurrent connections for each browser:

List the possible considerations for the browser to make such a decision.

Due to the limitation of the TCP protocol, only 65536 ports on the PC side can be used to send connections to the outside, and the operating system also has a limit on the number of half-open connections to protect the operating system's TCPIP stack resources from being quickly exhausted, so the browser is not good at sending out too many TCP connections. Instead, it takes the method of using TCP connections repeatedly or simply re-establishing TCP connections after using them.

If you use a blocked socket model to establish a connection, issuing multiple connections at the same time will cause the browser to open several more threads, and the thread is sometimes not a lightweight resource, after all, it is expensive to do a context switch.

This is the browser as a conscientious client protecting the server. Just like the collision detection mechanism of Ethernet, the client has to decide a waiting period when using common resources. When more than 2 clients want to use public resources, the strong evil client may make it impossible for weak clients to access public resources at all. In the past, Thunderbolt was sprayed because it was not a client with conscience, it did not take into account the pressure of the server as a client of HTTP protocol, and did not consider its obligation to give back the amount of uploads as a client of BT.

Taobao tengine

When we visit some websites, we will see that some of the js and css files in the code are obtained through a single request, and the above knowledge knows that there is a limit to the number of concurrent browser requests, but it may speed up the response if you merge multiple records into one request.

The tengine used by Taobao is a nginx-based web server that has been open source since the end of 11 years. Open source module nginx-http-concat, can merge multiple files in a response message.

Installation

Install third-party module nginx-http-concat for the first time

Wget http://tengine.taobao.org/download/tengine-2.2.0.tar.gzwget https://github.com/alibaba/nginx-http-concat/archive/master.zip-O nginx-http-concat-master.zipunzip nginx-http-concat-master.ziptar-xzvf tengine-2.2.0.tar.gzcd tengine-2.2.0

Configure compilation and installation

. / configure-prefix=/usr/local/nginx-with-http_stub_status_module-with-http_ssl_module-add-module=../nginx-http-concat-master make make install

If you have already installed Nginx, just configure a third-party plug-in. Nginx-V, check the version of Nginx, and if not, download the corresponding version.

Just execute the code.

. / configure-prefix=/usr/local/nginx-with-http_stub_status_module-with-http_ssl_module-add-module=../nginx-http-concat-mastermake

After compiling successfully

# Please back up the nginx execution file cp / objs/nginx / usr/local/nginx/sbin/nginx before replication

Kill Nginx and restart it.

Configuration

Add the following configuration to the location section:

Location / static/css/ {concat on; concat_max_files 20; concat_unique off; concat_types text/css application/javascript;}

Merger mode

This is the end of http://static.52itstyle.com/static/css/??index.css,common.css?v=20171111 's article on "how to merge Nginx request connections and accelerate website access". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

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