Nginx uses logrotate to split the log

Source: Internet
Author: User
Tags error handling parent directory
System Environment

Ubuntu 14.04LTS
Nginx 1.4.7 Edit the Nginx file under Logrotate

$ Vim/etc/logrotate.d/nginx
/usr/local/nginx/logs/*.log {//log location
    su root list   //Use root permission  , if not used  may report permissions related to the issue following the mention
    daily//    run once a day
    Missingok  //If the log file is missing, do not error continue to perform the next
    rotate 7   // Log save 7 days
    dateext//File suffix is a date format, that is, after the cut file is: xxx.log-20131216.gz So, if commented out, cut out is by the number increment, that is said before xxx.log-1 this format
    Notifempty   //If it is an empty file, do not dump  the permissions of Create 0640 root/log file
    sharedscripts
    prerotate
        if [-d/etc/logrotate.d/httpd-prerotate]; then \
            run-parts/etc/logrotate.d/httpd-prerotate; \
        fi \
    endscript
    postrotate
        [-s/run/ Nginx.pid] && kill-usr1 ' cat/run/nginx.pid '
    endscript
}

The file with the date in the back is generated, which indicates success.
Test

$/usr/sbin/logrotate-f/etc/logrotate.d/nginx 
//If a file is generated indicates a successful configuration
Add to Crontab
12:10 Daily * * * *  /usr/sbin/logrotate-f/etc/logrotate.d/nginx
Error Handling

May report this error if no SU root list is added

... insecure permissions (It ' s world writable or writable by group which are not ...
... error:skipping "/usr/local/nginx/logs/access.log" because parent directory ...

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.