Linux nginx log split by day instance

Source: Internet
Author: User

Linux nginx log split by day instance

Nginx Log has a small disadvantage, the log file has always been one, will not be automatically cut, if the traffic is very large, will cause the log file is very large, not easy to manage

That's what we need to do. Produce one log file per day by date

Ideas

Rename the default log file to today's date at 0 o ' Day and reopen the new log file

Use timed tasks to execute scripts, rename and reopen log files in scripts

You can reopen the log file by sending a USR1 signal to the Nginx main process


Realize

#/bin/bash

#备份日志的路径
Bakpath= '/home/nginx/logs '

#nginx日志路径
Logpath= '/usr/local/nginx/logs '

#在备份路径下创建年月子目录
Mkdir-p $bakpath/$ (date +%y)/$ (date +%m)

#移动日志文件到备份路径, and renamed to date format
MV $logpath/access.log $bakpath/$ (date +%y)/$ (date +%m)/access.$ (date +%y%m%d). log

MV $logpath/error.log $bakpath/$ (date +%y)/$ (date +%m)/error.$ (date +%y%m%d). log

#用 USR1 signal let nginx reopen log file
KILL-USR1 ' Cat/usr/local/nginx/logs/nginx.pid '

Linux nginx log split by day instance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.