关于Nginx目录下访问日志占用太多空间

/ Linux / 0 条评论 / 230浏览

装了web服务程序过后,只要服务一直开着,访问日志就会一直变大,打开一看还全TM是这样的访问:

211.149.224.192 - - [04/Jan/2019:16:26:53 -0500] "POST /zuos.php HTTP/1.1" 200 1261 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0"
211.149.224.192 - - [04/Jan/2019:16:26:53 -0500] "POST /zuoss.php HTTP/1.1" 200 1261 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0"
211.149.224.192 - - [04/Jan/2019:16:26:53 -0500] "POST /zuoshss.php HTTP/1.1" 200 1261 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0"
211.149.224.192 - - [04/Jan/2019:16:26:53 -0500] "POST /boots.php HTTP/1.1" 200 1261 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0"
211.149.224.192 - - [04/Jan/2019:16:26:53 -0500] "POST /she.php HTTP/1.1" 200 1261 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0"
211.149.224.192 - - [04/Jan/2019:16:26:54 -0500] "POST /s.php HTTP/1.1" 200 1261 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0"
211.149.224.192 - - [04/Jan/2019:16:26:54 -0500] "POST /qw.php HTTP/1.1" 200 1261 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0"
211.149.224.192 - - [04/Jan/2019:16:26:54 -0500] "POST /test.php HTTP/1.1" 200 1261 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0"
211.149.224.192 - - [04/Jan/2019:16:26:54 -0500] "POST /caonma.php HTTP/1.1" 200 1261 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0"
211.149.224.192 - - [04/Jan/2019:16:26:55 -0500] "POST /ss.php HTTP/1.1" 200 1261 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0"
211.149.224.192 - - [04/Jan/2019:16:26:55 -0500] "POST /wcp.php HTTP/1.1" 200 1261 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0"
211.149.224.192 - - [04/Jan/2019:16:26:55 -0500] "POST /u.php HTTP/1.1" 200 1261 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0"
211.149.224.192 - - [04/Jan/2019:16:26:57 -0500] "POST /uuu.php HTTP/1.1" 200 1261 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0"
211.149.224.192 - - [04/Jan/2019:16:26:57 -0500] "POST /sss.php HTTP/1.1" 200 1261 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0"
211.149.224.192 - - [04/Jan/2019:16:26:57 -0500] "POST /1.php HTTP/1.1" 200 1261 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0"
211.149.224.192 - - [04/Jan/2019:16:26:57 -0500] "POST /2.php HTTP/1.1" 200 1261 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0"
211.149.224.192 - - [04/Jan/2019:16:26:57 -0500] "POST /core.php HTTP/1.1" 200 1261 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0"
211.149.224.192 - - [04/Jan/2019:16:26:58 -0500] "POST /qaz.php HTTP/1.1" 200 1261 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0"

这样的信息着没有什么用,可以删了。 写了个定时任务定时清理nginx的访问日志。 先写个清理日志的shell脚本:

#!/bin/bash
# clear access_log and error_log on schedule
echo "clear" > access.log
echo "clear" > error.log

然后加一个定时任务每天凌晨3点执行脚本:

crontab -e
0 3 * * * /scripts/clear.sh

这样每到设置时间的点上,访问日志占用就会清空