目录
一、下载软件包
二、安装依赖
yum -y install gcc pcre-devel zlib-devel openssl openssl-devel
三、安装Nginx
#解压
tar -zxvf nginx-1.20.2.tar.gz
#进入NG目录
cd ./nginx-1.20.2
#配置
./configure --prefix=/usr/local/nginx
#编译
Make
make install
四、启动&停止
#启动
/usr/local/nginx/sbin/nginx
#重新加载配置
/usr/local/nginx/sbin/nginx -s reload
#停止
/usr/local/nginx/sbin/nginx -s stop
五、配置systemd方式管理NG
vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=The Nginx HTTP Server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s stop PrivateTmp=true
[Install]
WantedBy=multi-user.target
六、启动&停止
systemctl start nginx.service #(启动nginx服务)
systemctl stop nginx.service #(停止nginx服务)
systemctl enable nginx.service #(设置开机自启动)
systemctl disable nginx.service #(停止开机自启动)
systemctl status nginx.service #(查看服务当前状态)
systemctl restart nginx.service #(重新启动服务)
systemctl list-units --type=service #(查看所有已启动的服务)
七、实验测试
配置 /usr/local/nginx/conf/nginx.conf