方法一:使用Systemd
1.創(chuàng)建服務(wù)單元文件
sudo vi /etc/systemd/system/nginx.service
2.編輯配置文件
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target
[Service]
Type=forking
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
3.啟動(dòng)nginx服務(wù)
sudo systemctl enable nginx.service
4.重啟系統(tǒng)嘗試一下
reboot
關(guān)機(jī)后,我們發(fā)現(xiàn)連接不上了
然后等待一會(huì)兒,結(jié)果出來了~
方法二:使用rc.local
1.編輯rc.local
sudo vi /etc/rc.d/rc.local
2.添加命令
在文件中添加以下行,這將在系統(tǒng)啟動(dòng)時(shí)執(zhí)行啟動(dòng)NGINX的命令:
/usr/sbin/nginx
保存并關(guān)閉文件。文章來源:http://www.zghlxwxcb.cn/news/detail-704802.html
3.為`rc.local·添加可執(zhí)行權(quán)限
sudo chmod +x /etc/rc.d/rc.local
確保rc.local文件的所有者和組都是root:文章來源地址http://www.zghlxwxcb.cn/news/detail-704802.html
sudo chown root:root /etc/rc.d/rc.local
到了這里,關(guān)于CentOS7設(shè)置nginx服務(wù)開機(jī)自啟【開機(jī)自啟】的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!