systemd管理nginx

首先安装nginx,此处不做赘述。

保存以下内容到/lib/systemd/system/nginx.service文件。

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

注意:将上面内容中的路径改为实际的路径。

重载systemd配置文件

systemctl daemon-reload

启动服务

systemctl start nginx.service

开机启动

systemctl enable nginx.service

更多命令

systemctl reload nginx.service 重新加载nginx服务

systemctl stop nginx.service 停止nginx服务

原文地址:https://www.cnblogs.com/liyuchuan/p/10970789.html