Nginx log rollback

Source: Internet
Author: User
Nginx log rollback-Linux Enterprise Application-Linux server application information. The following is a detailed description. Author: shunz, source: http://shunz.net/2008/07/nginx_log_rotation.html

Nginx is a Web server software developed using the new Linux 2.6 kernel epoll mechanism, which can greatly improve the I/O performance of Web access, especially small file access. It is a solution to the c10k problem. According to some tests, Nginx is 10 times more efficient than Apache, and from my previous tests, its concurrency performance is indeed much better than Apache. Nginx is short and concise, so although some core web functions are well supported, some expansion functions are not supported yet. For example, Nginx currently does not support log output through pipe, therefore, cronolog is not supported for log truncation and rollback by time. An alternative solution is provided below:
CODE :#! /Bin/sh
Log_dir = "/var/log/httpd"
Yesterday = 'date + % Y % m % d-d'-1 day''
Lastday = 'date + % Y % m % d-d'-1 month''
/Bin/rm $ {log_dir}/access. $ {lastday}. log
/Bin/rm $ {log_dir}/error. $ {lastday}. log
/Bin/mv $ {log_dir}/access. log $ {log_dir}/access. $ {yesterday}. log
/Bin/mv $ {log_dir}/error. log $ {log_dir}/error. $ {yesterday}. log
Kill-USR1 'cat/var/run/nginx. Pi'
/Bin/gzip $ {log_dir}/access. $ {yesterday}. log &
/Bin/gzip $ {log_dir}/error. $ {yesterday}. log &

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.