Nginx merges request connections and speeds up website access examples

Nginx merges request connections and speeds up website access examples

Preface

As one of the best web servers in the world, Nginx's advantages are self-evident. Let's talk about how Nginx merges request connections.

Quick Facts

When we browse the web, an important factor affecting the browsing speed is the number of concurrent browsers. To put it simply, the number of concurrent tasks is the number of tasks that are performed simultaneously when browsing a web page.

Of course, the browser's concurrent request limit is for the same domain name. There is a certain limit on the number of requests under the same domain name at the same time. Requests exceeding the limit will be blocked.

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

List the possible considerations for the browser to make this decision

  • Due to the limitation of TCP protocol, the PC has only 65536 ports available for external connections, and the operating system also limits the number of half-open connections to protect the TCPIP protocol stack resources of the operating system from being exhausted quickly. Therefore, the browser should not issue too many TCP connections. Instead, it should reuse the TCP connection after it is used up or simply re-establish the TCP connection.
  • If a blocking socket model is used to establish a connection, issuing multiple connections at the same time will cause the browser to have to open several more threads, and threads are sometimes not considered lightweight resources. After all, the cost of a context switch is not small.
  • This is the browser acting as a conscientious client to protect the server. Just like the collision detection mechanism of Ethernet, the client must decide a waiting period by itself when using public resources. When more than two clients want to use public resources, the stronger evil client may cause the weaker clients to be completely unable to access the public resources. Xunlei was criticized in the past because it was not a conscientious client. As an HTTP protocol client, it did not consider the pressure on the server, and as a BT client, it did not consider its obligation to feedback the upload volume.

Taobao tengine

When we visit some websites, we will see that some js and css files in the code are obtained through one request. The above knowledge knows that the number of concurrent browser requests is limited, but if multiple records are merged into one request, the response speed may be accelerated.

The tengine used by Taobao is a web server based on nginx, which has been open source since the end of 2011. The open source module nginx-http-concat can merge multiple files into one response message.

Install

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

wget http://tengine.taobao.org/download/tengine-2.2.0.tar.gz
wget https://github.com/alibaba/nginx-http-concat/archive/master.zip -O nginx-http-concat-master.zip
unzip nginx-http-concat-master.zip
tar -xzvf tengine-2.2.0.tar.gz
cd tengine-2.2.0

Configuration, 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 Nginx has already been installed, just configure the third-party plug-in. Nginx -V, check the version of Nginx. If it is not available, 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-master
make

After successful compilation

#Please back up the nginx executable file before copying cp /objs/nginx /usr/local/nginx/sbin/nginx

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;
}

Merge method

http://static.52itstyle.com/static/css/??index.css,common.css?v=20171111

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Speed ​​up nginx performance: enable gzip and cache
  • Detailed explanation of how to configure Nginx to obtain user IP when using CDN acceleration
  • Nginx cache acceleration configuration method under WIN
  • Use nginx-http-concat module to merge static resource files in nginx
  • Solution to the unknown directive that cannot be opened due to Nginx configuration file problems

<<:  Summarize the problems encountered in using Vue Element UI

>>:  Solution to the problem that MySQL in Windows system cannot input and display Chinese

Recommend

Detailed usage of Linux text search command find

The find command is mainly used to find directori...

HTML insert image example (html add image)

Inserting images into HTML requires HTML tags to ...

VScode Remote SSH remote editing and debugging code

The latest Insider version of Visual Studio Code ...

Detailed explanation of the execution plan explain command example in MySQL

Preface The explain command is the primary way to...

How to write the parent and child directories of HTML relative paths

How to indicate the parent directory ../ represent...

MySQL independent index and joint index selection

There is often a lack of understanding of multi-c...

Summary of SQL deduplication methods

When using SQL to extract data, we often encounte...

Detailed explanation of Js class construction and inheritance cases

The definition and inheritance of classes in JS a...

Example of how to quickly delete a 2T table in mysql in Innodb

Preface This article mainly introduces the releva...

The use of MySQL triggers and what to pay attention to

Table of contents About Triggers Use of triggers ...

Tutorial on installing MySQL 8.0.11 using RPM on Linux (CentOS7)

Table of contents 1. Installation preparation 1. ...

VMware vsphere 6.5 installation tutorial (picture and text)

vmware vsphere 6.5 is the classic version of vsph...

Vue2 implements provide inject to deliver responsiveness

1. Conventional writing in vue2 // The parent com...

Detailed Tutorial on Installing VirtualBox 6.0 on CentOS 8 / RHEL 8

VirtualBox is a free and open source virtualizati...