首页
归档
笔记
树洞
搜索
友言

文章详情

Interesting People Record Interesting.

/ 计算机网络/服务器 / 文章详情

service nginx start|stop|reload 报错:Failed to reload nginx.service: Unit not found.【解决方案】

Sonder
2021-08-18
2560字
6分钟
浏览 (3.3k)

在执行service nginx start|stop|reload 的时候报错:Failed to reload nginx.service: Unit not found

是因为nginx没有有添加到系统服务,手动手动添加一个即可。

1.创建文件

复制代码
vim /etc/init.d/nginx

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

执行

复制代码
# chmod 755 /etc/init.d/nginx

# chkconfig –add nginx

4.之后就可以使用,绝对没毛病

复制代码
service nginx start | stop | reload

转自:http://www.zhuhongliang.com/archives/238

下一篇 / 如何在 NUXT项目中使用 NProgres

🎯 相关文章

💡 推荐文章

🕵️‍♂️ 评论 (0)