在centos下启动nginx出现Failed to start nginx.service:unit not found
错误的原因就是没有添加nginx服务,所以启动失败。
解决方法:
1. 在/root/etc/init.d/目录下新建文件,文件名为nginx
或者用命令在根目录下执行:# vim /etc/init.d/nginx (注意vim旁边有一个空格)
2. 插入以下代码
#!/bin/sh # nginx - this script starts and stops the nginx daemin # # chkconfig: - 85 15# description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server# processname: nginx # config: /usr/local/nginx/conf/nginx.conf # pidfile: /usr/local/nginx/logs/nginx.pid# Source function library. . /etc/rc.d/init.d/functions# Source networking configuration. . /etc/sysconfig/network# Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0nginx="/usr/local/nginx/sbin/nginx"prog=$(basename $nginx)NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"lockfile=/var/lock/subsys/nginxstart() {[ -x $nginx ] || exit 5[ -f $NGINX_CONF_FILE ] || exit 6echo -n $"Starting $prog: "daemon $nginx -c $NGINX_CONF_FILEretval=$?echo[ $retval -eq 0 ] && touch $lockfilereturn $retval}stop() {echo -n $"Stopping $prog: "killproc $prog -QUITretval=$?echo[ $retval -eq 0 ] && rm -f $lockfilereturn $retval}restart() {configtest || return $?stopstart}reload() {configtest || return $?echo -n $"Reloading $prog: "killproc $nginx -HUPRETVAL=$?echo}force_reload() {restart}configtest() {$nginx -t -c $NGINX_CONF_FILE}rh_status() {status $prog}rh_status_q() {rh_status >/dev/null 2>&1}case "$1" instart)rh_status_q && exit 0$1;;stop)rh_status_q || exit 0$1;;restart|configtest)$1;;reload)rh_status_q || exit 7$1;;force-reload)force_reload;;status)rh_status;;condrestart|try-restart)rh_status_q || exit 0;;*)echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"exit 2esac
3. 用命令进入此目录
# cd /etc/init.d
4. 依此执行以下命令
# chmod 755 /etc/init.d/nginx
# chkconfig --add nginx (注意add前面是两个短横线-)
5. 开启nginx
# service nginx start
转载于:https://www.cnblogs.com/ansibee/p/8087476.html
在centos下启动nginx出现Failed to start nginx.service:unit not found相关推荐
- mysqld服务启动失败, Failed to restart mysqld.service: Unit not found.
mysqld服务启动失败, Failed to restart mysqld.service: Unit not found. -bash-4.2# service mysqld restart Re ...
- CentOS 7报错:Failed to start xxx.service: Unit is masked
如果开启服务的时候遇到Failed to start xxx.service: Unit is masked. 意识是这个服务锁定了,可执行如下命令开启: systemctl unmask xxx.s ...
- kali搭建bind9 dns服务器启动问题:Failed to restart bind9.service: Unit bind9.service not found.
安装的名字虽然是bind9,但是启动要用named. 就是service named restart 国内找不到答案 参考答案:https://gitlab.isc.org/isc-projects/ ...
- Failed to start firewalld.service: Unit is masked
centos7 启动防火墙失败:Failed to start firewalld.service: Unit is masked. 解决: 执行" systemctl start fire ...
- 【QA】启动时间同步服务失败:Failed to start ntpd.service: Unit not found
Failed to start ntpd.service: Unit not found 重启大数据集群后,启动时间同步服务,出现异常: 解决办法: 首先看一下服务列表里有没有这个服务: system ...
- 【Linux - mysql】linux下mysql报Failed to restart mysqld.service: Unit not found
笔者使用 service mysqld restart 重启mysql服务的时候,报了Failed to restart mysqld.service: Unit not found 估计也就是服务名 ...
- Failed to start mongod.service: Unit not found
其实自己用惯的是MYSQL,然后项目最后一步完善数据读写的部分,本来打算用mysql的,然而在centOS系统上发现安装总是出问题,后来查找一下资料,发现centOS系统上一般用的是Mariadb,这 ...
- 【已解决】Failed to start cron.service: Unit cron.service not found.
问题 输入sudo service cron start 重启下cron服务,报错: Failed to start cron.service: Unit cron.service not found ...
- Failed to restart docker.service: Unit is masked.真正的解决办法
启动docker时报错 [root@localhost deployScript]# systemctl restart docker Failed to restart docker.service ...
- Centos7 Failed to start xxx.service: Unit not found
Centos7 Failed to start xxx.service: Unit not found 一.查看 systemctl list-unit-files --type=service // ...
最新文章
- 基于Jittor框架实现LSGAN图像生成对抗网络
- MVC使用Flash来显示图片
- pfile和spfile的区别
- 复仇者联盟与IntelliJ IDEA也很配哦
- HNUSTOJ-1257 You are my brother
- 搜索引擎其实是一个读库
- vue项目实现登录(sessionStorage 存储 token)
- 趣挨踢 | 关于遗留代码的那些事儿
- c语言程序设计语言描述,C语言程序设计题目描述(详).txt
- Netty 服务 接收新数据
- 编译原理中:短语,直接短语,句柄
- java容器的理解_java容器的理解
- 穿越者的真正优势是人才
- 爬虫(二)-创建项目应用
- 【心理学】心理学效应
- python编程师app_python大师编程课app
- 引起计算机故障的因素有哪些,电源故障引起的电脑问题有哪些
- token失效 判断access_微信开发-ACCESS TOKEN 过期失效解决方案
- 第一章 接口测试基础
- K-SVD: An Algorithm for Designing Overcomplete Dictionaries for Sparse Representation
热门文章
- OSChina 周日乱弹 ——身价上亿,然而找不到女朋友 你信么?
- junit4X系列--Builder、Request与JUnitCore
- C#写的NoSQL开源项目/系统(系列)
- eclipse中统计代码行数
- 计算机科学与技术真的会掉头发吗,大学“最辛苦”的三个专业,“脱发率”很高,毕业后却都很吃香!...
- android从服务端获取json解析显示在客户端上面,Android服务端获取json解析显示在客户端上面.doc...
- pytroch一机多卡训练
- 关于语音文字的互转识别的猜想
- 使用分布式+you-get多任务下载视频
- hadoop如何学习?