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 goodNginxUploaded to the mainframe/usr/toolsDirectory.
  • Due to theNginxIs made up ofC/C++Language, so to compile it must use the relevant compiler, forC/C++Language compiler, the most used isgccwithgcc-c++, and these two compilers are inCentOS7Is not installed, so you need to install these two compilers first. The operation is shown below

  • Install dependency libraries, basicNginxFunctionality depends on some basic libraries during installationNginxThese libraries need to be installed in advance. As shown in the figure below

  • Create unzip directory in/usrcreateappsDirectory for storing decompression

  • Unpack theNginxThat will beNginxunzip/usr/appsDirectory.

  • generatemakefileIn theNginxDecompress the directory to runmakeCommand to complete the compilation, but prompts that no target was specified and no compilation file was sentmakefile. Compile commandmakeNeed to compile files frommakefileTo compile, so you need to compile a file before compilingmakefile, the use ofconfigureCommand to generate the file.

  • Compile and install, as shown below

Nginx command

  • View command options./nginx -h, you can viewNginxCommand options, as shown in the following figure

  • ./nginx -vTo viewNginxThe following figure shows the version information

  • ./nginx -VTo view moreNginxVersion information, for examplegccVersion,OpenSSLAs shown in the figure below

  • ./nginx -tTests whether the configuration file is correct. By default, only the default configuration file is testedconf/nginx.conf;./nginx -TTest whether the configuration file is correct and display the content of the configuration file../nginx -tqDuring the configuration file test, only error information is displayed instead of non-error information. Can be combined with-cOption specifies the configuration file to test. Note that it will not startNginx.

  • ./nginx -s stop/quitYou can stopNginx.
    • ./nginx -s stop: Forcibly stopNginx, regardless of whether the current worker process is processing work
    • ./nginx -s quit: Graceful stopNginxTo stop the current work process after it completes the current work.

  • ./nginx -s reloadWithout restartNginxUnder the premise of reloadingNginxConfiguration file, smooth startup

  • ./nginx -PThe specifiedNginxPath for saving the configuration file.
  • ./nginx -c fileTo start theNginx.-cIf 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 defaultNginxIn the installation directoryconf/nginx.conf.

test

  • Disable the firewall, as shown in the following figure

  • Browser access due toNginxThe default port number is80“, so type directly in the browserNginxThe hostIP, you can seeNginxWelcome page, as long as you see the following page informationNginxThe installation is successful.