CentOS8.4安裝Nginx1.20.1並通過systemd管理


一.安裝

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM