1. Introduction to Nginx

What is Nginx Nginx is an HTTP server. Is a high performance HTTP server and reverse proxy server developed using C language. Nginx is a high-performance HTTP/reverse proxy server and E-mail (IMAP/POP3) proxy server. Developed by Russian programmer Igor Sysoev, Nginx was officially tested to support up to 50,000 concurrent links with very low CPU, memory and other resource consumption. Nginx was designed and developed by Russian Igor Sysoev. Development began in 2002 and the first public announcement was made on October 4, 2004. The official website is nginx.org/. It is a free open source high-performance HTTP Proxy server and Reverse Proxy product, and it can also provide IMAP/POP3 mail Proxy services and other functions. Its high concurrency performance is very good, the official test can support 50,000 concurrency; Low runtime memory and CPU usage, simple configuration, easy to use, and very stable operation.

2, Nginx common features

In fact, there are many Nginx features, here I only introduce a few commonly used functions, you can refer to the official website.

Reverse proxy

This is one of the main functions of the Nginx server as a WEB server. When a client sends a request to the server, it passes through the Nginx server first, and the server distributes the request to the corresponding WEB server. Forward agent is the agent of the client, while the reverse proxy is a proxy server, Nginx in terms of reverse proxy service, through the use of regular expressions for related configuration, take different forwarding strategy, the configuration is quite flexible, and configure the back-end forwarding the request, completely don’t care about how the network environment, you can specify any IP address and port number, Or other types of connections, requests, etc.

② Load balancing

This is also one of the most commonly used functions of Nginx. Load balancing, on the one hand, distributes a single heavy load to multiple network nodes for parallel processing. After each node finishes processing, the results are summarized and returned to the user, which can greatly improve the processing capacity of the network system. On the other hand, a large number of front-end concurrent requests or data traffic is distributed to multiple back-end network nodes for processing, which can effectively reduce the corresponding waiting time of front-end users. Nginx load balancing is the latter aspect, mainly to a large number of front-end access or traffic diversion, to ensure the front-end user access efficiency, and can reduce the back-end server processing pressure.

③ Web cache

On many good Web sites, Nginx can serve as a front-end cache server, which is used to cache front-end requests to improve the performance of the Web server. Nginx makes a local copy of the content that the user has already accessed, so that the data can be accessed again within a certain period of time without the need to send a request through the Nginx server back end. Reduce network congestion, reduce data transmission delay, and improve user access speed.

3, Nginx installation and use

Nginx installation

Nginx installation can be divided into Windows and Linux platforms. The Windows version of Nginx server is less efficient than the Linux version of Nginx server. And the actual use is generally Linux platform Nginx server. So we will introduce the Linux version in the future.

Nginx download address:Nginx.org/en/download…

(2) Windows version installation

We unzip the nginx-1.20.1.zip file we downloaded in the previous step to the current directory.

The decompression directory is as follows:

Here are the main folders in this directory:

1. Conf directory: stores the main configuration files of Nginx. Many functions are implemented by configuring the nginx.conf file in this directory, which will be described in detail later.

2, Docs directory: Nginx server files, including Nginx server licenses, OpenSSL licenses, PCRE licenses, and Zlib licenses. It also includes version change notes for this version of the Nginx server upgrade, as well as README documentation.

3. HTML directory: contains two static web files with the suffix.html, which are related to the running of the Nginx server.

Logs directory: stores Nginx server running log files.

Nginx. exe: start the nginx server exe file. If the nginx.conf file in the conf directory is correctly configured, use this file to start the nginx server.

Start nginx

Double-click the nginx.exe file in the directory after decompression, and a flash screen appears, then the startup is successful.

Enter http://localhost or http://localhost:80 in the address box of the browser.

Close nginx

Go to the decompressed directory and run the following command:

 nginx.exe -s stop
Copy the code

Alternatively, you can open the task Manager, find the nginx process, and right-click to end it.

Nginx startup and shutdown

Nginx -v Displays the nginx version number and compilation information. Start nginx starts nginx nginx -s stop Quick stop and close Nginx Nginx -s quit Normally stop or close Nginx Nginx -s reload configuration file modification Reload Nginx -t Tests the correctness of the Nginx configuration file and the details of the configuration file Task /fi “Imagename eq nginx.exe” Windows command box to view the nginx process command