Linux system server, nginx log cutting and saving tutorial.
When it comes to Nginx log cutting and saving, you can use the logrotate tool. Here's a simple tutorial to help you achieve this:
- First, make sure you have installed the logrotate tool. On most Linux distributions, you can install it using the following command:
sudo apt-get install logrotate # Debian/Ubuntu sudo yum install logrotate # CentOS/RHEL
- Create a configuration file for Nginx logs. In the terminal, use a text editor (such as vi or nano) to create a new file, such as
nginx-logrotate.conf
:
sudo nano /etc/logrotate.d/nginx-logrotate.conf
- In the opened configuration file, enter the following:
/path/to/nginx/logs/*.log { daily # 每天切割日志文件 missingok # 如果日志文件不存在也不会报错 rotate 7 # 保留最近7个日志文件 compress # 压缩旧的日志文件 delaycompress # 延迟压缩,直到下次切割时才压缩 notifempty # 如果日志文件为空,则不切割 create 0644 <user> <group> # 设置新生成的日志文件的权限和所有者,用具体的用户和组替换<user>和<group> sharedscripts # 在所有日志文件都处理完毕后,运行一次脚本 postrotate # 切割后执行的命令 /usr/sbin/nginx -s reopen endscript # 脚本结束}
Please note that you need to replace /path/to/nginx/logs/
with the path to your actual Nginx logs directory and <user> Replace </user>
and <group></group>
with the appropriate user and group.
- Save and close the configuration file.
logrotate is now configured to cut Nginx log files every day and keep the most recent 7 log files. You can customize options in the configuration file according to your needs, such as the number of log files to retain and the cutting frequency.
To avoid excessive disk space being taken up, be sure to check and clean old log files regularly. You can use crontab or other scheduled task tools to run cleanup commands regularly, such as deleting old log files within a certain time range.
The above is the detailed content of Linux system server, nginx log cutting and saving tutorial.. For more information, please follow other related articles on the PHP Chinese website!

Do you have trouble downloading or sending attachments in Outlook 365? Sometimes, Outlook doesn’t show them for some unknown reason, so you are unable to see them. In this post on php.cn Website, we collect some use tips for attachments not showing.

When V Rising players try to join a server that is close to or already full, they may encounter the “V Rising connection timed out” issue. If you are one of them, you can refer to this post from php.cn to get solutions. Now, keep on your reading.

Windows supplies real-time protection via Windows Security. But this feature may prevent you from doing something it thinks are dangerous. In this situation, you may want to temporarily turn on real-time protection. This php.cn post will show you how

Microsoft has started working on next year’s Windows updates very early. Recent rumors state that the next update in 2024 might be Windows 11 24H2 rather than Windows 12. Everything is uncertain now. php.cn will now take you to see some related infor

The error 0x80030001 often happens when you are attempting to copy files. The error code will be accompanied by a message that tells “unable to perform requested operation”. If you are struggling with this error, you can read this article on php.cn W

On February 13, 2024, Microsoft released KB5034765 (OS builds 22621.3155 and 22631.3155) for Windows 11 22H2 and Windows 11 23H2. This security update brings you many new improvements and bug fixes. You can learn how to download and install Windows 1

Device Manager is widely used when you need to fix some computer issues. You can check the problematic devices and decide to uninstall or update device drivers. Besides, you can also set Power Management settings in Device Manager. However, you may f

When Backup and Restore (Windows Backup) fails to work, you can choose to reset it to default. How to restore Windows Backup to default in Windows 11/10? php.cn will guide you to easily do this thing in 2 ways and let’s go to see them.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool