sh file manages the startup and shutdown of nginx in Linux

Note:
The premise is that nginx is installed in the system and the environment variables have been configured.
Environment: CentOS8.5
nacos version: 1.24.0

  1. Create a nginx_ctl.sh (you can name it as you wish). Just copy and paste the entire text below.
#!/bin/bash

NGINX_PATH="/usr/local/nginx/sbin/nginx"  # Nginx可执行文件路径 别忘了换成你自己安装的路径

start() {
    echo "Starting Nginx..."
    $NGINX_PATH
}

stop() {
    echo "Stopping Nginx..."
    $NGINX_PATH -s stop
}

restart() {
    echo "Restarting Nginx..."
    $NGINX_PATH -s reload
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        restart
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
        ;;
esac

exit 0

2. In the terminal, use the following command to grant execution permissions to the sh file:

 chmod +x  nginx_ctl.sh
  1. Now, you can do this by running in the terminal
./nginx_ctl.sh start 启动
./nginx_ctl.sh stop 停止
./nginx_ctl.sh restart  重启

Guess you like

Origin blog.csdn.net/qq_37120477/article/details/131908957