Nginx log segmentation implementation

Source: Internet
Author: User

Nginx log segmentation Abstract: nginx does not support log segmentation, but its PID can be used to achieve log segmentation. I have read several online examples, but they are not clear. So I decided to write one by myself. Maybe I forgot one day and can start learning again. I hope I can make it clear that I will not bother to watch it next time or when others are watching it. Because nginx does not support log segmentation, its PID can be used to achieve log segmentation. 1. write the log Separation program nginx-log.sh #/bin/bash savepath_log = '/logs/nginx/logs' # The path where the log will be stored nglogs ='/usr/local/nginx/logs' # nginx log Path mkdir-p $ savepath_log/$ (date + % Y) /$ (date + % m) mv nglogs/access. log % savepath_log/$ (date + % Y)/$ (date + % m)/access. % (data + % Y % m % d ). log mv nglogs/error. log % savepath_log/$ (date + % Y)/$ (date + % m)/error. % (data + % Y % m % d ). log kill-USR1 'cat/usr/local/nginx/logs/nginx. pid '# Save the script and add it to cront in linux The AB daemon allows this script to be executed at every day to split logs every day. 2. Modify the File Permission so that it can be executed. Chmod 755 nginx-log.sh 3. you can check which scheduled tasks are crontal-l 4. open the daemon and enter crontal-e # In programming mode. For example, press I with vi. add the task to be executed in the daemon, usually the log is divided at 0 0 0 ****/logs/nginx/nginx-log.sh # The execution file storage path is good, wait until tomorrow to go to the log directory to see the implementation results ..

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.