Introduction to the
Nginx is a lightweight, high-performance, HTTP-based, reverse proxy server, static Web server. Nginx was originally developed by Igor Sysoev(Igor Seroyev) in C language for rambler.ru, the second most visited site in Russia. The first version was released in October 2004. Large domestic sites, such as Baidu, JINGdong, Sina, NetEase, Taobao, etc., all use Nginx. Nginx’s official website: nginx.org
Proxy server
Forward agent
hidden
Over the wall
To speed up
The cache
The reverse proxy
Protect the hidden
Distributed routing
Load balancing
Dynamic and static separation
A forward proxy is different from a reverse proxy
- A forward proxy client knows which server it is accessing, while a reverse proxy does not.
- The forward proxy server is installed on the client and the reverse proxy server is installed on the server.
The characteristics of Nginx
High concurrency
An Nginx server can have up to 1000 concurrent requests without any configuration. If the hardware conditions allow, Nginx can support up to 50,000-100,000 concurrent requests (in addition to Nginx Settings, Linux hosts need to do a lot of setup to cooperate with Nginx).
Compare this to Tomcat, which has a default concurrency of 150 (no configuration) and becomes very slow when more than 150 users access a Servlet at the same time.
Low consumption
According to official test results, 10,000 inactive connections consume only 2.5m of memory in Nginx, which is not a problem for general Dos attacks, but can be a problem for DDos attacks as well. A simple example to understand Dos and DDos attacks is as follows:
-
Dos attacks: the service is not available, it attacks the unavailability of information security, for example: a lot of people on a ATM machine to withdraw money, the man is to take money to take 20000 dollars, but every time he only take 100, lead to the back of the people can’t use the ATM machine to withdraw money, although the attack, but it submitted are legitimate requests.
-
DDos attack: This is a distributed system that has a bunch of ATMs, so I have a bunch of people, like the Dos above, take over all the ATMs.
Hot deployment
The Nginx version can be upgraded smoothly under the premise of 7*24 hours uninterrupted service, Nginx configuration file smooth modification, that is, without stopping the upgrade of Nginx, modify and replace the Nginx configuration file.
High availability
The reason why Nginx can achieve high concurrency is that it has many workers. When some of these workers stop working due to problems, the overall operation of the whole system will not be affected, because other workers will take over the faulty threads.
High extension
The reason why Nginx has so many users today is that many features have been developed and modularized. If you need any features, you just need to install the corresponding extension module. According to the language used to write the extension module, it can be divided into two categories: C language extension module and LUA script extension module.
Download and install Nginx
Nginx download
Go to Nginx’s official website: nginx.org to download the corresponding version.
Nginx installation
- First will download the good
Nginx
Uploaded to the mainframe/usr/tools
Directory. - Due to the
Nginx
Is made up ofC/C++
Language, so to compile it must use the relevant compiler, forC/C++
Language compiler, the most used isgcc
withgcc-c++
, and these two compilers are inCentOS7
Is not installed, so you need to install these two compilers first. The operation is shown below
- Install dependency libraries, basic
Nginx
Functionality depends on some basic libraries during installationNginx
These libraries need to be installed in advance. As shown in the figure below
- Create unzip directory in
/usr
createapps
Directory for storing decompression
- Unpack the
Nginx
That will beNginx
unzip/usr/apps
Directory.
- generate
makefile
In theNginx
Decompress the directory to runmake
Command to complete the compilation, but prompts that no target was specified and no compilation file was sentmakefile
. Compile commandmake
Need to compile files frommakefile
To compile, so you need to compile a file before compilingmakefile
, the use ofconfigure
Command to generate the file.
- Compile and install, as shown below
Nginx command
- View command options
./nginx -h
, you can viewNginx
Command options, as shown in the following figure
./nginx -v
To viewNginx
The following figure shows the version information
./nginx -V
To view moreNginx
Version information, for examplegcc
Version,OpenSSL
As shown in the figure below
./nginx -t
Tests whether the configuration file is correct. By default, only the default configuration file is testedconf/nginx.conf
;./nginx -T
Test whether the configuration file is correct and display the content of the configuration file../nginx -tq
During the configuration file test, only error information is displayed instead of non-error information. Can be combined with-c
Option specifies the configuration file to test. Note that it will not startNginx
.
./nginx -s stop/quit
You can stopNginx
../nginx -s stop
: Forcibly stopNginx
, regardless of whether the current worker process is processing work./nginx -s quit
: Graceful stopNginx
To stop the current work process after it completes the current work.
./nginx -s reload
Without restartNginx
Under the premise of reloadingNginx
Configuration file, smooth startup
./nginx -P
The specifiedNginx
Path for saving the configuration file../nginx -c file
To start theNginx
.-c
If the configuration file path is specified, no information is displayed after the startup is successful. If no configuration file is specified, yes is loaded by defaultNginx
In the installation directoryconf/nginx.conf
.
test
- Disable the firewall, as shown in the following figure
- Browser access due to
Nginx
The default port number is80
“, so type directly in the browserNginx
The hostIP
, you can seeNginx
Welcome page, as long as you see the following page informationNginx
The installation is successful.