LOGS_PATH="/home/log/nginx/logs"
ARCHIVE_YEAR=$(date -d "yesterday" "+%Y")
ARCHIVE_MONTH=$(date -d "yesterday" "+%m")
if [ -r /opt/nginx/nginx.pid ]; then
mkdir -p "${LOGS_PATH}/${ARCHIVE_YEAR}/${ARCHIVE_MONTH}"
mv "${LOGS_PATH}/access.log" "${LOGS_PATH}/${ARCHIVE_YEAR}/access_${ARCHIVE_MONTH}.log"
kill -USR1 $(cat "/nginx/nginx.pid")
sleep 1
gzip "${LOGS_PATH}/${ARCHIVE_YEAR}/access_${ARCHIVE_MONTH}.log"
else
echo "Nginx might be down"
fi
`