Systemd管理Nginx

使用Systemd管理nginx

在我们安装好nginx以后 ,在systemd下创建一个名为nginx.server的文件如下

vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target

需要注意的是以下配置文件

PIDFile=/var/run/nginx.pid

要与nginx的配置文件里面的pid文件位置相同

vim /usr/local/nginx/conf/nginx.conf
#pid        logs/nginx.pid;
pid        /var/run/nginx.pid;

通过systemd来启动nginx

systemctl daemon-reload && systemctl start nginx

你可能感兴趣的:(运维)