微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Centos7配置nginx服务、开机自启动

启动、停止、重启、重载、检查服务:
6: service httpd start|stop|restart|reload|status
7: systemctl start|stop|restart|reload|status httpd.service

允许、禁止服务自启动:
6: chkconfig httpd on|off
7: system enable|disable httpd.service

列出服务:
6: chkconfig –list
7: systemctl list-unit-files –type=service 或 ls /etc/systemd/system/*.wants/

添加服务:
6: chkconfig httpd –add
7: systemctl daemon-reload

可以先通过上述命令查询是否已经配置Nginx服务,如果没有

centos7:

服务文件

#systemd 下的 system 或 usr 创建 Nginx.service 文件
vim /usr/lib/systemd/system/Nginx.service 

#Nginx服务配置到该文件中
#服务描述性的配置
[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
#pid文件位置 
#要与Nginx配置文件中的pid配置路径一致,这个很重要,否则会服务启动失败
PIDFile=/var/run/Nginx.pid
#启动前检测 Nginx配置文件 是否正确
ExecStartPre=/usr/sbin/Nginx -t -c /usr/local/Nginx/conf/Nginx.conf
#启动
ExecStart=/usr/sbin/Nginx -c /usr/local/Nginx/conf/Nginx.conf
#重启
ExecReload=/bin/kill -s HUP $MAINPID
#关闭
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target 

启动服务

$ systemctl start Nginx.service

设置开机自启

$ systemctl enable Nginx.service

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐