“This is the 12th day of my participation in the Gwen Challenge in November. See details of the event: The Last Gwen Challenge 2021”.

Previous articles:

I met Nginx

Environment to prepare

The official website of Nginx is nginx.org

Open the website and you can see the following page content

The official download site for Nginx is nginx.org/en/download… Of course, you can also select “Download” on the right of the home page to enter the version download page. On the download page we will see the following:

Get Nginx source code

nginx.org/download/

You can view all versions of Nginx from the above website, and select the version you want to download. Download you can download it directly from Windows and upload it to the server, or you can download it directly from the server. In this case, you need to prepare a server.

Preparing the Server System

Vm or server

Centos system, centos 7 or 8

1. Check the kernel of centos

Prepare an operating system with a 2.6 or later kernel, because Linux2.6 or later kernel supports epoll, and Nginx needs to solve the problem of high concurrency, so we need to have such a version requirement.

We can use the uname -a command to query the Linux kernel version.

2. Ensure that centos can be connected to the Internet
ping www.baidu.com
Copy the code
3. Disable the firewall

This requirement is only for those who are not clear about the firewall rules of the Linux system, it is recommended that we close the firewall, the firewall off, you can save many problems encountered in the follow-up process.

The shutdown can be done in the following two ways:

Systemctl stop firewalld Disable the running firewall. After the system restarts, the firewall will be enabled again. Systemctl disable firewalld Disable the firewall permanently. The firewall is still disabled systemctl status firewalld Checks the firewall statusCopy the code

Nginx installation mode

There are two ways to install Nginx:

  • Install via Nginx source codeCopy the code
  • Install via yumCopy the code

Nginx source code installation

Nginx source code installation:

GCC compiler

Nginx is written in C, so to run Nginx you need to install a compilation tool. GCC is an open source collection of compilers used to handle a wide variety of languages, including C.

Use the yum install -y GCC command to install

After the installation is successful, you can run GCC –version to check whether GCC is successfully installed

PCRE

Nginx needs to use the PCRE library (the Perl Compatible Regular Expression library) for compilation, because both the Rewrite module and the HTTP core module use the PCRE Regular expression syntax.

You can use the yum install -y pcre pcre-devel command to install

You can run the RPM -qa pcre pcre-devel command to check whether the installation is successful

zlib

The zlib library provides the developer’s compression algorithm, and we need to use gzip compression in various modules of Nginx, so we need to install the library and source code zlib and zlib-devel

You can use the yum install -y zlib zlib-devel command to install

After the installation, run the RPM -qa zlib zlib-devel command to check whether the installation is successful

OpenSSL

OpenSSL is an open source software library package that applications can use to securely communicate and avoid eavesdropping.

SSL: Short for Secure Sockets Layer Protocol (SSL), which provides secret transport over the Internet. The goal is to ensure the confidentiality and reliability of communication between two applications. In Nginx, if the server needs to provide secure web pages, it needs to use the OpenSSL library, so we need to install the OpenSSL library file and its development package.

You can run the yum install -y openssl openssl-devel command to install openssl-devel

After the installation, run the RPM -qa openssl openssl-devel command to check whether the installation is successful

The above commands, one by one is more troublesome, we can also use a command to install

yum install -y gcc pcre pcre-devel zlib zlib-devel openssl openssl-develComplete the installation.

The installation process

(1) Go to the official website to find the link of the version to be downloaded, and then use the wget command to download it

Wget HTTP: / / http://nginx.org/download/nginx-1.16.1.tar.gzCopy the code

(2) It is recommended that you carry out package management of downloaded resources

Mkdir -p nginx/core mv nginx-1.16.1.tar.gz nginx/coreCopy the code

(3) the decompression

The tar - XZF nginx - 1.16.1. Tar. GzCopy the code

(4) Enter the resource file and find configure

./configure
Copy the code

(5) compilation

make
Copy the code

(6) installation

make install
Copy the code

Yum install

Install yum-utils

sudo yum  install -y yum-utils
Copy the code

(2) Add the yum source file

vim /etc/yum.repos.d/nginx.repo
Copy the code
[nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true [nginx-mainline] name=nginx mainline repo  baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ gpgcheck=1 enabled=0 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=trueCopy the code

(3) Check whether the installation is successful

yum list | grep nginx
Copy the code

(4) Install using yum

yun install -y nginx
Copy the code

(5) Check the installation location of nginx

whereis nginx
Copy the code

(6) Start the test

The difference between a source installation and a YUM installation:

The following describes a command:./nginx -v. You can run this command to view the version and configuration information of the installed nginx.

Simple to install

Yum install

Unzip the Nginx directory

Run the tar -zxvf nginx-1.16.1.tar.gz command to decompress the downloaded resources and go to the compressed directory. The following information is displayed

Content Explanation:

Auto: stores compile-related scripts

CHANGES: indicates the version change record

Changes. ru: Record of CHANGES to the Russian version

Conf :nginx default configuration file

Configure :nginx automatic script. Configure :nginx automatic script.

(1) Detect the environment and generate C code according to the environment detection results

(2) Generate the Makefile required for compiling the code

Contrib: There are a few special script files that are explained in detail in the README

HTML: Nginx native HTML pages, visit the Nginx home page and error page

LICENSE: describes a LICENSE file

Man: Nginx man manual

README:Nginx reading guide

SRC: source code for Nginx

Nginx directory structure analysis

If you want to use the tree tool, you can check the file directory structure on centos. If you want to use the tree tool, you can check the file directory structure on centos. /usr/local/nginx = /usr/local/nginx = /usr/local/nginx = /usr/local/nginx = /usr/local/nginx

Conf: directory for all nginx configuration files

CGI(Common Gateway Interface) Common Gateway [Interface], the main problem to solve is to send a request and data from the client, the server to obtain the request and data can call CGI [program] processing and the corresponding results to the client a standard specification.

Fastcgi. conf: fastCgi-related configuration file

Fastcgi. Conf. Default: fastcgi. Conf backup files

Fastcgi_params: Parameter file for fastCGI

Fastcgi_params. default: Backup file of fastcgi parameters

Scgi_params: parameter file of SCGI

Scgi_params. default: backup file of SCGI parameters

Uwsgi_params: Parameter file of UWSGi

Uwsgi_params. default: backup file of UWSGi parameters

Mime. Types: Records the mapping between the HTTP content-type value and the file name extension

Mime. Types. Default: mime types of backup files

Nginx.conf: This is the core configuration file of nginx, which is very important and will be the focus of our study

Nginx. Conf. Default: nginx. Conf backup files

The koi-UTF, KoI-Win, and win-UTf files are all configuration files related to encoding translation mappings that are used to convert one encoding to another

HTML: Stores two static HTML pages that come with nginx

50x. HTML: failed page after access failure

Index.html: The default home page for successful access

Logs: Log entry file. When the nginx server is started, there are three files in this file: access.log error.log and nginx.pid.

Sbin: stores the executable program file nginx

Nginx is a command used to control the start and stop of nginx.

Nginx server start and stop command

Nginx: Nginx -h: Nginx -h: Nginx -h: Nginx -h: Nginx -h: Nginx -h

Direct./nginx is the start commandCopy the code

-? And -h: Displays the help information

-v: prints the version number and exits

-v: prints the version number and configuration information and exits

-t: tests whether the syntax of the nginx configuration file is correct and exits

-t: tests whether the syntax of the nginx configuration file is correct, lists the used configuration file information, and exits

-q: Disables non-error messages during configuration tests

-s: indicates the signal.

-stop [quickly close, similar to TERM/INT signal] -quit [gracefully close, similar to quit signal] -reopen [reopen log file similar to USR1 signal] -reload [similar to HUP signal]Copy the code

-p:prefix specifies the Nginx prefix path (default: /usr/local/nginx-/)

-c:filename specifies the path to the Nginx configuration file. (Default: conf/nginx.conf)

-g: used to supplement the Nginx configuration file and specify the global configuration to be applied to the Nginx service at startup