在CentOS7下將nginx添加到systemctl

1、正確安裝Nginx
安裝Nginx請自行百度

2、將Nginx添加到systemctl
在/usr/lib/systemd/system/下新建文件“nginx.service”
編輯nginx.service,輸入如下內容

[Unit]
Description=nginx - high performance web server 
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

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

[Install]
WantedBy=multi-user.target

編輯保存

3、將Nginx設置爲開機啓動

[root@localhost init.d]# systemctl enable nginx.service

測試啓動Nginx

[root@localhost init.d]# systemctl start nginx.service

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章