[root@centos7 ~]# vim /usr/lib/systemd/system/nginx.service [Unit] Description=The Nginx HTTP Server daemon #必須加守護神不然會報錯 #描述信息 After=network.target re... ...
[root@centos7 ~]# vim /usr/lib/systemd/system/nginx.service [Unit] Description=The Nginx HTTP Server daemon #必須加守護神不然會報錯 #描述信息 After=network.target remote-fs.target nss-lookup.target #指定啟動nginx之前需要其他的其他服務,如network.target等 [Service] Type=forking #Type為服務的類型,僅啟動一個主進程的服務為simple,需要啟動若幹子進程的服務為forking ExecStart=/usr/local/nginx/sbin/nginx #設置執行systemctl start nginx後需要啟動的具體命令. ExecReload=/usr/local/nginx/sbin/nginx -s reload #設置執行systemctl reload nginx後需要執行的具體命令. ExecStop=/bin/kill -s QUIT ${MAINPID} #設置執行systemctl stop nginx後需要執行的具體命令. [Install] WantedBy=multi-user.target [root@centos7 ~]#systemctl daemon-reload #多載入幾遍就可以了 #然後就nginx就可以跟大眾服務一樣啦! [root@centos7 ~]#systemctl start nginx [root@centos7 ~]#systemctl start renginx [root@centos7 ~]#systemctl reload nginx [root@centos7 ~]#systemctl stop nginx