How to regularly clean up Nginx logs in Linux system

  
                

Nginx log files how to clean up, will become bigger and bigger, affecting the operation of Nginx server, the following small series will introduce you to the way to clean up Nginx logs in Linux, let's understand.

nginx log files require manual segmentation, create a script file clear_log.sh

File Path /usr/local/nginx/clear_log.sh

vi clear_log.sh . Enter the following content

#! /bin/bash

cp /usr/local/nginx/logs/error.log /usr/local/nginx/error-$(date -d “yesterday” +“%Y%m%d&rdquo ;).log

#Copy the original error log file first, please fill in according to your actual log path

cat /dev/null /> /usr/local/nginx/logs/error. Log

#清Error log file

cp/usr/local/nginx/logs/access.log /var/log/nginx/access/access-$(date -d “yesterday&rdquo ; +“%Y%m%d”).log

#Copy the original normal access log first

cat /dev/null 》 /usr/local/nginx/logs/access .log

#Clear the original normal access log

Create the dellog.sh file, path /usr/local/nginx

vi dellog.sh

#! /bin/sh

find /usr/nginx/logs/error -mtime +7 -type f -name /*.log

Copyright © Windows knowledge All Rights Reserved