Nginx Log Management configuration

Source: Internet
Author: User

1. Create log directory

Nginx's default log directory may have a smaller hard disk space, so create a log directory based on the disk's space condition

Example: Mkdir/backup/nginx_logs

2. Modify Nginx configuration file

Configure the Nginx log directory to point to the directory you just created

In the configuration file, write:

Write on the server or HTTP or location block according to the time situation, this example is written in the server block

Access_log/backup/nginx_logs/access.log combined;

The above combined is the default log format for Nginx, and if you do not write it, you need to redefine it.

In this case, the combined is written directly, and this format awstats also recognized.

3, the use of logrotate management

The logrotate system comes with automatic timing and starts at 4:02

The configuration file is as follows:

/backup/nginx_logs {

Daily

missingok

rotate 7

nocompress

prerotate

/usr/local/awstats/wwwroot/cgi-bin/awstats.pl-update -config =yoursite.com

endscript

postrotate

if [-f/usr/local/nginx/logs/nginx.pid]; then

kill-usr1 ' cat/usr/local/nginx/logs/nginx.pid '

fi

endscript

Before each rotate, will call Awstats generate statistics, rotate will be sent to the Nginx after the log to write people a new blank log file

Logrotate will use the/etc/logrotate.conf configuration file and all the configuration files in/ETC/LOGROTATE.D, so no need to change the logrotate configuration, just go to/ETC/LOGROTATE.D to add the above configuration file

Write the configuration file must be careful, or debug is troublesome, such as you put the configuration file nocompress removed, thought will default to use the compress in/etc/logrotate.conf, actually not, if/etc/ Configuration file Error in LOGROTATE.D, Logrotate will not be replaced with/etc/logrotate.conf, and there is no error message in/var/log/messages and the system's outgoing mail, unless the configuration file has an obvious error, the/var /log/messages and the system's outgoing mail response.

Nginx Log Management configuration

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.