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

 

posted on 2021-08-25 19:06  zhealks  阅读(304)  评论(0)    收藏  举报