ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

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

2019-03-19 13:56:08  阅读:225  来源: 互联网

标签:httpd 服务 service Centos7 nginx systemctl usr 自启动


启动、停止、重启、重载、检查服务:
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

 

标签:httpd,服务,service,Centos7,nginx,systemctl,usr,自启动
来源: https://blog.csdn.net/Liu_jalon/article/details/88658737

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有