1 基本信息
服务器OS : Linux CENTSO 7.9
待安装的Nginx版本: NGINX 15.12
2 安装过程
step1 下载安装包
# cd /usr/local/software/
# wget http://nginx.org/download/nginx-1.15.12.tar.gz
step2 解压安装包
# cd /usr/local/software/
# tar -zxvf nginx-1.15.12.tar.gz -C ./
step3 安装依赖项
解决异常: ./configure时报的异常:
./configure: error: the HTTP rewrite module requires the PCRE library. ...
参考文献
安装nginx时候提示:./configure: error: the HTTP rewrite module requires the PCRE library. - CSDN
# yum -y install gcc gcc-c++ automake autoconf libtool make
# yum -y install pcre-devel openssl openssl-devel
step4 配置与安装前检查
cd /usr/local/software/nginx-1.15.12
./configure --prefix=/usr/local/nginx
--conf-path=/usr/local/nginx/conf
--with-http_stub_status_module
- ./configure --help
- --prefix=PATH 设置软件安装目录路径
- --with-http_stub_status_module 启用HTTP_Stub_Status模块,状态信息统计模块,用于返回一个Nginx状态信息统计信息页面。管理员访问这个页面可以获取Nginx的请求处理、当前连接、等待连接等统计信息,一般用于监控Nginx的运行状态。默认情况下不构建此模块。
- --conf-path=PATH 设置配置文件安装目录路径
![](https://img2020.cnblogs.com/blog/1173617/202106/1173617-20210616102946461-412976900.png)
![](https://img2020.cnblogs.com/blog/1173617/202106/1173617-20210616101635656-1651848565.png)
step5 编译
cd /usr/local/software/nginx-1.15.12
make
![](https://img2020.cnblogs.com/blog/1173617/202106/1173617-20210616102841019-654973154.png)
step6 安装
cd /usr/local/software/nginx-1.15.12
make install
![](https://img2020.cnblogs.com/blog/1173617/202106/1173617-20210616102800170-851223618.png)
step7 查验版本
/usr/local/nginx/sbin/nginx -V
![](https://img2020.cnblogs.com/blog/1173617/202106/1173617-20210616102014926-1066752529.png)
step8 开启网内外部主机访问端口
- 方法1 关闭防火墙
防火墙管理,可参见:
systemctl stop firewalld
// service firewalld status
// service iptables stop
- 方法2 仅开启对应端口
systemctl start firewalld
firewall-cmd --permanent --add-port=80/tcp
systemctl restart firewalld
step9 查验运行状态
![](https://img2020.cnblogs.com/blog/1173617/202106/1173617-20210616102554032-799680585.png)
![](https://img2020.cnblogs.com/blog/1173617/202106/1173617-20210616103457075-1453323816.png)
![](https://img2020.cnblogs.com/blog/1173617/202106/1173617-20210616104615626-445668429.png)
3 Nginx卸载
step1 全局查找Nginx相关文件
sudo find / -name nginx*
![](https://img2020.cnblogs.com/blog/1173617/202106/1173617-20210616113159773-1328989763.png)
whereis nginx
![](https://img2020.cnblogs.com/blog/1173617/202106/1173617-20210616113524338-44774275.png)
step2 删除查找出来的所有Nginx相关文件
yum remove nginx
// 先使用yum清理
sudo rm -rf <fileOrDir>
// 最后,依次手动删除查找出来的nginx文件(夹)
![](https://img2020.cnblogs.com/blog/1173617/202106/1173617-20210616113625575-558458487.png)
![](https://img2020.cnblogs.com/blog/1173617/202106/1173617-20210616114728733-1739438557.png)
删除之后,便可重新安装nginx了。