How to install Nginx under Centos7

1. Introduction to Nginx
Nginx (engine x) is a high-performance HTTP and reverse proxy web server, and also provides IMAP/POP3/SMTP services. Nginx was developed by Igor Sysoyev for the second most visited Rambler.ru site in Russia (Russian: Рамблер). The public version 1.19.6 was released on December 15, 2020.
It releases its source code under a BSD-like license and is known for its stability, rich feature set, simple configuration files, and low system resource consumption. On January 25, 2022, nginx 1.21.6 was released.
Nginx is a lightweight web server/reverse proxy server and email (IMAP/POP3) proxy server, released under the BSD-like protocol. Its characteristic is that it occupies less memory and has strong concurrency capability. In fact, the concurrency capability of nginx is better than other web servers of the same type.

2. Nginx dependency installation
Before installing Nignx, several dependency packages need to be installed: pcre, openssl, zlib, nginx.
If there is no network, then find the latest version of pcre on the sourceforge website (https://sourceforge.net/projects/pcre/)

insert image description here
Enter the command to download in the terminal, and download the installation package to the server /usr/src/ directory

insert image description here
Then find the compressed package and decompress it

tar -zxvf pcre-8.45.tar.gz

insert image description here
insert image description here

After the decompression is complete, enter the pcre directory, execute ./configure to compile, and after the compilation is complete, execute the make command

If there is a network, directly execute the command to download and install
yum install -y gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel

insert image description here
3. Nginx download
The latest stable version can be downloaded from the official website http://nginx.org/en/download.html
insert image description here
Upload the Nginx installation package to the virtual machine through xftp

insert image description here
Unzip the nginx installation package
tar -zxvf nginx-1.24.0.tar.gz

insert image description here

insert image description here
insert image description here

You can also download wget http://nginx.org/download/nginx-1.24.0.tar.gz through the command
. After the download is complete, you also need to decompress

4. Nginx configuration
Execute the command ./configure in the /usr/local/nginx/nginx-1.24.0 file directory
insert image description here
and then execute the make command

insert image description here

insert image description here
5. Start Nginx
Find the nginx directory in the virtual machine directory and find the sbin/ directory. You
insert image description here
need to start the Nginx file in the sbin/ directory, enter the sbin file and use the command ./nginx to start the program
(PS: close the command ./nginx - s stop
reload command ./nginx -s reload)

insert image description here
insert image description here

Access to the IP of the virtual machine, if the access fails, it may be due to the firewall, you need to close the firewall, or open the access port 80 of the firewall, you can
insert image description here
query and configure firewall-cmd --list-all through the command, where ports are set ports, you need Open running access to port 80

insert image description here
Use the command to set firewall-cmd --add-port=80/tcp --permanent to
insert image description here
restart the firewall systemctl reload firewalld
to view the status of the firewall systemctl status firewalld
insert image description here
to start the firewall systemctl start firewalld
to close the firewall systemctl stop firewalld

After restarting to set the port, restart the firewall, and check again that the port number has been set successfully.
insert image description here

Visit the virtual machine address again, as shown in the figure, Nginx starts successfully and can be accessed normally.

insert image description here

Guess you like

Origin blog.csdn.net/lssffy/article/details/131439893