Nginx environment setup: installation and uninstallation

Table of contents

1. Uninstall

2. Installation


Note: If you use yum to install nginx directly, the default installation path is: /usr/share/nginx/

In the following way we specify the installation directory

1. Uninstall

Because I already have nginx service on my previous virtual machine, I can first introduce the uninstallation method of nginx:
In fact, it is very simple, just find all nginx files, and then Delete all ngixn files:

Find:

[root@centos222 ~]# find / -name nginx 
/var/lib/nginx
/var/log/nginx
/usr/lib64/nginx
/usr/share/nginx
/usr/local/nginx
/usr/local/nginx/sbin/nginx
/soft/nginx
/soft/nginx/nginx-1.6.2/objs/nginx

delete:

[root@centos222 ~]# rm -rf /var/lib/nginx/
[root@centos222 ~]# rm -rf /var/log/nginx/
[root@centos222 ~]# rm -rf /usr/share/nginx/
[root@centos222 ~]# rm -rf /usr/local/nginx/

Then you can use the following command to check again

[root@centos222 ~]# yum remove nginx
参数 nginx 没有匹配
不删除任何软件包

If there is no need to delete any software packages, it proves that they have been deleted!

Below we will start the formal installation tutorial.

2. Installation

1. First, we can create a directory file soft to store the software, and then create the nginx directory under this directory file.

mkdir  /soft && mkdir /soft/nginx/

Note: If it prompts that soft already exists, you only need to execute the subsequent mkdir.

2. Download the Nginx installation package. You can upload the offline environment package through the FTP tool, or obtain the installation package online through the wget command:

wget https://nginx.org/download/nginx-1.21.6.tar.gz

If there is a wget command displayed, you can use yum to install it:
 

 yum -y install wget

3. Unzip the compressed package you just downloaded:

tar -xvzf nginx-1.21.6.tar.gz 

4. Download the dependent libraries and packages required to install nginx, and specify the download directory: /soft/nginx/

yum install --downloadonly --downloaddir=/soft/nginx/ gcc-c++ pcre pcre-devel4 zlib zlib-devel openssl-devel

Of course, you can also use the yum command to download directly with one click:

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

 5. Use the rpm command to build dependent packages one by one, or install all dependent packages with one click through the following command:

First go to the /soft/nginx/ directory just now, and then use the following command to build the dependency package:

rpm -ivh --nodeps *.rpm

6. Enter the decompressed nginx directory, enter the decompressed nginx directory, and then execute the Nginx configuration script to configure the environment in advance for subsequent installation. The default location is / Under the usr/local/nginx/ directory (the directory can be customized):

cd nginx-1.21.6/
./configure --prefix=/soft/nginx/

7. Compile and install nginx:

make && make install

8. Now move to the /soft/nginx/ directory and enter ll to see the files generated after installing nginx:

[root@centos222 nginx]# ll
总用量 4
drwxr-xr-x. 2 root root 4096 11月 23 11:25 conf
drwxr-xr-x. 2 root root   40 11月 23 11:25 html
drwxr-xr-x. 2 root root    6 11月 23 11:25 logs
drwxr-xr-x. 2 root root   19 11月 23 11:25 sbin

8. Then we can modify the conf/nginx.conf configuration file:

vim conf/nginx.conf

9. After the modification is completed, we can start nginx:

sbin/nginx -c conf/nginx.conf

Then we can view the progress and check whether it is started:

ps -aux | grep nginx

 As you can see from the picture, it has started normally.

10. Here are some other commands about nginx:

sbin/nginx -t -c conf/nginx.conf # 检测配置文件是否正常
sbin/nginx -s reload -c conf/nginx.conf # 修改配置后平滑重启(平滑重启不会中断)
sbin/nginx -s quit # 优雅关闭Nginx,会在执行完当前的任务后再退出
sbin/nginx -s stop # 强制终止Nginx,不管当前是否有任务在执行

11. Now we try to release port 80 on the firewall to test whether the nginx service is normal.

firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
firewall-cmd --zone=public --list-ports

You can see that port 80 is indeed allowed.

Then we try to access 192.168.159.200:80 in the browser (just fill in the IP address and port you set) to see if you will see the main page of the nginx service. 

You can see that the nginx service has been successfully accessed. The installation of nginx has been introduced here!

I will use Docker in my blog post later. For the installation of Docker, you can refer to a blog I wrote before:docker installation

Guess you like

Origin blog.csdn.net/qq_68163788/article/details/134519218