1.安装依赖包
##一键安装上面四个依赖
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
2.下载并 解压安装包
//创建一个文件夹
cd /usr/local
mkdir nginx
cd nginx
//下载tar包
wget http://nginx.org/download/nginx-1.21.6.tar.gz
tar -xvf nginx-1.21.6.tar.gz
3.安装nginx
//进入nginx目录
cd /usr/local/nginx
//进入目录
cd nginx-1.13.7
//执行命令 考虑到后续安装ssl证书 添加两个模块
./configure --with-http_stub_status_module --with-http_ssl_module
//执行make命令
make
//执行make install命令
make install
4.配置nginx.conf
vim /usr/local/nginx/conf/nginx.conf
5.启动nginx服务
# 校验配置文件是否正确
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf -t
# 启动nginx
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
其他命令
## 查看ngxin进程
ps -ef | grep nginx
## 开放80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
## 重启防火墙
firewall-cmd --reload
## 重启nginx
/usr/local/nginx/sbin/nginx -s reload
卸载nginx
## 停止nginx服务
ps -ef|grep nginx
## 删除进程
kill 进程Id
/usr/local/nginx/sbin/nginx -s stop
## 删除ngxin文件
whereis nginx
find / -name nginx
rm -rf /usr/local/nginx
## 卸载nginx依赖
yum remove nginx