在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 0

nginx="/usr/local/nginx/sbin/nginx"

prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

lockfile=/var/lock/subsys/nginx

start() {

    [ -x $nginx ] || exit 5

    [ -f $NGINX_CONF_FILE ] || exit 6

    echo -n $"Starting $prog: "

    daemon $nginx -c $NGINX_CONF_FILE

    retval=$?

    echo

    [ $retval -eq 0 ] && touch $lockfile

    return $retval

}

stop() {

    echo -n $"Stopping $prog: "

    killproc $prog -QUIT

    retval=$?

    echo

    [ $retval -eq 0 ] && rm -f $lockfile

    return $retval

}

restart() {

    configtest || return $?

    stop

    start

}

reload() {

    configtest || return $?

    echo -n $"Reloading $prog: "

    killproc $nginx -HUP

    RETVAL=$?

    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" in

    start)

        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 2

esac

3. 用命令进入此目录

  # cd /etc/init.d

4. 依此执行以下命令

# chmod 755 /etc/init.d/nginx

# chkconfig --add nginx   (注意add前面是两个短横线-)

5. 开启nginx

# service nginx start

时间: 2024-10-25 20:31:52

在centos下启动nginx出现Failed to start nginx.service:unit not found的相关文章

mysqld服务启动失败, Failed to restart mysqld.service: Unit not found.

-bash-4.2# service mysqld restart Redirecting to /bin/systemctl restart mysqld.serviceFailed to restart mysqld.service: Unit not found. 并不存在 mysqld 的服务, -bash-4.2# -bash-4.2# chkconfig -list -list: unknown option -bash-4.2# chkconfig --list Note: Thi

CentOS 7 防火墙 出现Failed to start iptables.service: Unit iptables.service failed to load

错误信息如下: [root]# service iptables start Redirecting to /bin/systemctl start iptables.service Failed to start iptables.service: Unit iptables.service failed to load: No such file or directory.解决方法如下: 一直用CentOS 6 习惯了,一下没适应过来.防火墙配置后执行service iptables sav

Failed to start mongod.service: Unit not found

其实自己用惯的是MYSQL,然后项目最后一步完善数据读写的部分,本来打算用mysql的,然而在centOS系统上发现安装总是出问题,后来查找一下资料,发现centOS系统上一般用的是Mariadb,这是一个MYSQL的分支,说是因为甲骨文收购了MYSQL后,为了避免闭源的风险,社区开始使用并维护这个MariaDB. 然后我安装Maria,一直卡在那里... 可是话说为什么我一个前端,要搞这些东西呢... 然后我还是退出来使用mongodb算了... 然后启动mongodb的时候报这个错误:Fai

CentOS7.2安装mariadb-server,解决Failed to start mysqld.service: Unit not found

当输入命令 ~]# systemctl start mysql.service 要启动MySQL数据库是却是这样的提示 Failed to start mysqld.service: Unit not found 解决方法如下: 首先需要安装mariadb-server ~]# mariadb-server 启动服务 ~]# systemctl start mariadb.service 添加到开机启动 ~]# systemctl enable mariadb.service 至此完成! 可以测

CentOS7安装MySQL报错Failed to start mysqld.service: Unit not found解决办法

1 ~]# systemctl start mysql.service 要启动MySQL数据库是却是这样的提示 1 ~]# Failed to start mysqld.service: Unit not found 解决方法如下: 首先需要安装mysql-server 1 ~]# yum install -y mysql-server 启动服务 1 ~]# systemctl start mysqld.service 添加到开机启动 1 ~]# systemctl enable mysqld.

docker报错:Failed to restart docker.service: Unit not found.

前言:我之前安装好docker了,但是关机重启后,发现docker就没了 报错:Failed to restart docker.service: Unit not found. 解决方法: 1.重装大法,法力无边 a.先卸载上个版本的相关软件 yum -y  remove  docker  docker-common  docker-selinux  docker-engine b.安装docker 最详细最快部署docker::https://www.jianshu.com/p/9c96ea

docker安装完报错:Failed to start docker.service: Unit docker.service is masked

执行 systemctl start docker 报错 Failed to start docker.service: Unit docker.service is masked. 解决 systemctl unmask docker.service systemctl unmask docker.socket systemctl start docker.service 原文地址:https://www.cnblogs.com/chenqionghe/p/11478863.html

[ISSUE] [Centos] Centos Start Nginx Show: Failed to start nginx.service:unit not found

CMD Line:systemctl start nginx.serviceFailed to start nginx.service: Unit not found. Solution: 1.vim /etc/init.d/nginx #!/bin/sh # nginx - this script starts and stops the nginx daemin # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server,

CentOS7安装mysql后无法启动服务,提示Failed to start mysqld.service: Unit not found

首先:需要更新你的yum源,保证yum源最新. 1.安装: yum install -y mariadb-server 2.启动maria DB服务: systemctl start mariadb.service (说明:CentOS 7.x开始,CentOS开始使用systemd服务来代替daemon,原来管理系统启动和管理系统服务的相关命令全部由systemctl命令来代替.) 3.将mariadb服务添加至开机自启动: systemctl enable mariadb.service 原