说明:尝试使用CentOs8.5安装nginx1.9.9失败,make的时候报错了,后面降低版本为CentOs7.5安装成功了,参考文章:【精选】centos7安装nginx-1.9.9_linx centos nginx 1.9.9版本 nginx error log file: "/-CSDN博客
一、安装nginx编译所需环境
yum install -y gcc-c++ # 编译使用
yum install -y pcre pcre-devel # pcre库
yum install -y zlib zlib-devel # 文件解压缩
yum install -y openssl openssl-devel # 配置https服务需要
二、安装nginx
mkdir -p /home/local
cd /home/local
wget http://nginx.org/download/nginx-1.15.9.tar.gz
tar -zxvf nginx-1.15.9.tar.gz
cd nginx-1.15.9/
./configure --prefix=/usr/local/nginx/ --with-http_ssl_module --with-http_stub_status_module
make&&make install
cd /usr/local/nginx/sbin
./nginx # 启动
systemctl stop firewalld # 关闭防火墙
PATH=$PATH:/usr/local/nginx/sbin
echo "PATH=$PATH:/usr/local/nginx/sbin" >>/root/.bashrc
# 设置开机启动
echo "/usr/local/nginx/sbin/nginx">>/etc/rc.local
chmod +x /etc/rc.d/rc.local
netstat -anplut |grep nginx # 查看端口
ps aux | grep nginx # 查看进程
三、浏览器输入http://192.168.6.73访问
四、重启/关闭
cd /usr/local/nginx/sbin
./nginx -s reload # 重启nginx
./nginx -s quit # 关闭nginx
五、卸载nginx
ps aux | grep nginx
kill 994 # 根据进程ID杀进程
find / -name nginx # 查找nginx相关文件
rm -rf /usr/local/nginx # 删除编译文件
rm -rf /home/local/nginx-1.15.9 # 删除源文件
# 删除开机启动配置
rm -rf /etc/init.d/nginx