How to Install Nginx on Linux

Download the Nignx installation package

Nginx official website

Click download on the right
insert image description here
to select the version you want to download (I chose 1.14.2)
insert image description here

Preparation before installation

1. Is the gcc compiler installed?

#检查是否安装:
yum list installed | grep gcc
#安装:
yum install gcc -y

2. Whether the openssl library is installed

#检查是否安装:
yum list installed | grep openssl
#安装:
yum install openssl openssl-devel -y

3. Is the pcre library installed?

#检查是否安装:
yum list installed | grep pcre
#安装:
yum install pcre pcre-devel -y

4. Is the zlib library installed?

#检查是否安装:
yum list installed | grep zlib
#安装:
yum install zlib zlib-devel -y

One-time install command

yum install gcc openssl openssl-devel pcre pcre-devel zlib zlib-devel -y

Upload the installation package to Linux

I am using Xftp 7 to upload files
insert image description here

decompress

Unzip the ngnix file

tar -zxvf nginx-1.14.2.tar.gz -C /opt

After decompression, go to the nginx home directory, and then execute

#指定安装目录,=号两边没有空格
./configure  --prefix=/opt/nginx

then execute make

Then execute make install

Installation is complete

Open firewall ports

Check firewall open ports

firewall-cmd --list-all

Set an open port (nginx default port is 80)

sudo firewall-cmd --add-port=80/tcp --permanent

restart firewall

firewall-cmd --reload

Start the Nignx service

Switch to the sbin directory of the nginx installation directory to execute

./nginx

insert image description here

About 403Forbidden

If 403Forbodden appears, you can modify the configuration file
of nginx. 1. Go to the conf directory under the nginx installation directory.
2. Use the vim nginx.conf command to modify the configuration file
. 3. Configure the running user of the worker to be root
insert image description here
. 4. Save :wq
. restart nginx

./nginx -s reload

Guess you like

Origin blog.csdn.net/m0_60117382/article/details/123872739