系统:Linux Centos 7.9
1 安装必要安装包
gcc 、c++、pcre、zlib、openssl等
powershell
yum install -y gcc-c++
yum install -y pcre
yum install -y pcre-devel
yum install -y zlib
yum install -y zlib-devel
yum install -y openssl
yum install -y openssl-devel
2 下载Nginx
源码并解压
powershell
wget -c http://nginx.org/download/nginx-1.15.7.tar.gz
mkdir -p /usr/lib/nginx
tar -zxvf nginx-1.15.7.tar.gz -C /usr/lib/nginx
3 配置、编译和安装Nginx
powershell
cd /usr/lib/nginx/nginx-1.15.7 # 进入解压目录
./configure
make && make install
4 配置全局变量
powershell
vim /etc/profile # 编辑文件
source /etc/profile
添加内容
powershell
export NGINX_HOME=/usr/local/nginx
export PATH=${NGINX_HOME}/sbin:$PATH
5 启动、停止和重新加载Nginx
powershell
./nginx # 启动Nginx
./nginx -t # 检测是否有语法错误
./nginx -s reload # 重新加载配置文件
./nginx -s stop # 强制停止
6 设置开机自启
powershell
vim /etc/rc.local
/usr/local/nginx/sbin/nginx
chmod 755 /etc/rc.local