Nginx Log Cutting

Source: Internet
Author: User

To write a script :

vim/usr/local/sbin/logrotate.sh//Join


#!/bin/bash

D= ' date-d '-1 day "+%f"

[-d/tmp/nginx_log] | | Mkdir/tmp/nginx_log

mv/tmp/access.log/tmp/nginx_log/$d. Log

/etc/init.d/nginx Reload 2>/dev/null

cd/tmp/nginx_log/

Gzip-f $d. Log






#! /bin/bash

Datedir= ' Date +%y%m%d '

/bin/mkdir/home/logs/$datedir >/dev/null 2>&1
/bin/mv/home/logs/*.log/home/logs/$datedir
/bin/kill-hup ' Cat/var/run/nginx.pid '

Log Format

Log_format main ' $remote _addr-$remote _user [$time _local] $request '
" $status" $body _bytes_sent "$http _referer"
' "$http _user_agent" "$http _x_forwarded_for";



log_format main1 ' $proxy _add_x_forwarded_for-$remote _user [$time _local] '
" $request" $status $body _bytes_sent '
' "$http _referer" "$http _user_agent"; This log format is that IP not only records the proxy IP but also records the remote client real IP.


error Log error_log log level

The error_log level is divided into debug, info, notice, warn, error, crit default to Crit, which defines the format behind the log name as follows:
Error_log/your/path/error.log Crit;

Crit logs are minimal, and debug logs are logged the most. If your nginx encounters some problems, such as 502 more frequent, but see the default error_log does not see meaningful information, then you can adjust the level of the error log, when you tune to the error level, the content of errors logging will be richer.


Nginx Log Cutting

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.