centos7启动nginx失败


用yum安装nginx的话只需要

systemcel enable nginx.service

就可以启动服务了

但是我用的是源码安装,此时会报如下错误"

Failed to start nginx.service: Unit not found.

"

这时候我们需要在系统服务目录里面创建nginx文件

vi /lib/systemd/system/nginx.service

然后复制以下内容

[Unit]

Description=nginx
After=network.target
  
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp= true
  
[Install]
WantedBy=multi-user.target
 
完成后用systemctl start nginx.service就可以成功启动服务了
此时还可以把nginx添加为开机自启动
 
我这里完成之后启动服务的时候还出现一个错误

Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

用netstat -tnlp查看发现存在一个nginx进程

我们把它kill掉 netstat -tnlp 就可以成功地启动nginx了

 
 
 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM