nginx相关

定时切割nginx日志
#!/bin/bash #desc: cut nginx log #this script run at 00:00 LOG_PATH='/usr/local/nginx/logs/'; LOG_BACK_PATH='/home/www/log/'$(date -d '-1 days' +'%Y/%m/'); mkdir -p $LOG_BACK_PATH; cd $LOG_PATH && gzip access.log mv access.log.gz $LOG_BACK_PATH'access_'$(date +'%d')'.log.gz'; kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`;

crontab -e

0 0 * * * /bin/bash /bin/bash /root/tools/crond/nginxlog.sh 1>/dev/null 2>&1

 nginx管理脚本

#!/bin/bash
NGINXHOME=/usr/local/nginx
NGINX=$NGINXHOME/sbin/nginx

RETVAL=0
start(){
    nohup $NGINX > /dev/null 2>&1 &
    RETVAL=$?
    if [ $? -eq 0 ];then
        echo 'start OK'
    else
        echo 'start FAILED'
    fi
    return $RETVAL
}

stop(){
    echo 'Stoping nginx...'
    $NGINX -s stop
    echo 'stop ok'
}

restart(){
    stop
    sleep 2
    start
}

reload(){
    $NGINX -s reload
    echo 'reload ok'
}


case "$1" in
    start)
        start;;
    stop)
        stop;;
    restart)
        restart;;
    reload)
        reload;;
    chkconfig)
        $NGINX -t;;
    *)
        echo "Usage: $NGINX (start|stop|reload|chkconfig)"
        exit 1
esac
原文地址:https://www.cnblogs.com/bai-jimmy/p/4190810.html