一.安裝
1.配置yum源
CentOS8.4配置本地YUM源
2.解壓
tar -zxvf nginx-1.20.1.tar.gz
3.安裝依賴
yum -y install pcre-devel zlib zlib-devel openssl openssl-devel
4.配置,我的路徑是/opt/nginx/
./configure --prefix=/opt/nginx/
5.編譯&安裝
make
make install
二.配置systemd
1.新建nginx.service
vim /usr/lib/systemd/system/nginx.service
2.插入
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/opt/nginx/logs/nginx.pid
ExecStartPre=/opt/nginx/sbin/nginx -t -c /opt/nginx/conf/nginx.conf
ExecStart=/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf
ExecReload=/opt/nginx/sbin/nginx -s reload
ExecStop=/opt/nginx/sbin/nginx -s stop
ExecQuit=/opt/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
3.賦予執行權限
chmod +x /usr/lib/systemd/system/nginx.service
4.重啟systemd
systemctl daemon-reload
三.啟動並驗證
1.啟動
systemctl start nginx.service
2.開機自啟
systemctl enable nginx.service
3.驗證
curl localhost:80