


How to configure Debian Apache log rotation
This article introduces how to configure Apache log rotation in the Debian system, mainly using the logrotate
tool.
Step 1: Verify that logrotate
is installed
Check with the following command:
logrotate --version
If not installed, execute:
sudo apt-get update sudo apt-get install logrotate
Step 2: Locate the Apache log rotation configuration file
The configuration file is usually located in the /etc/logrotate.d/
directory, and the file name may be apache2
or httpd
. Use the following command to find:
ls /etc/logrotate.d/apache2 # or ls /etc/logrotate.d/httpd
Step 3: Edit the Apache log rotation configuration file
Open the configuration file using a text editor such as nano
or vim
:
sudo nano /etc/logrotate.d/apache2 # or sudo nano /etc/logrotate.d/httpd
Step 4: Configure logrotate
parameters
In the configuration file, you can customize the log rotation frequency, the number of retained log files, the compression method, etc. Here is a sample configuration:
<code>/var/log/apache2/*.log { daily missingok rotate 7 compress delaycompress notifempty create 640 root adm sharedscripts postrotate if [ -x /usr/sbin/invoke-rc.d ]; then /usr/sbin/invoke-rc.d apache2 reload >/dev/null 2>&1 fi endscript }</code>
Parameter description:
-
daily
: daily rotation. -
missingok
: No error is reported when the log file is missing. -
rotate 7
: Keep 7 log files. -
compress
: Compress old logs. -
delaycompress
: Delay compression until the next rotation. -
notifempty
: The empty log file does not rotate. -
create 640 root adm
: Create a new log file with permissions of 640, belongs to the main root, belongs to the group adm. -
sharedscripts
: When multiple log files are used, thepostrotate
script is executed only once. -
postrotate ... endscript
: The script executed after log rotation, reload the Apache configuration here. (Use more generalif [ -x ... ]
to check if the script exists)
Step 5: Test the configuration
Test the configuration with the following command:
sudo logrotate -d /etc/logrotate.d/apache2 # -d parameter is test mode and will not be actually executed
The -d
parameter is used for testing mode, and does not actually perform rotation, and only checks whether the configuration syntax is correct. If there is no error, then execute sudo logrotate /etc/logrotate.d/apache2
for actual rotation.
Step 6: Confirm the timing task
logrotate
is usually automatically executed by the system cron task. You can check the /etc/cron.daily/logrotate
file to make sure it exists and is configured correctly.
After completing the above steps, your Debian system Apache log rotation configuration is completed. If you have any questions, please check the configuration file syntax and permission settings.
The above is the detailed content of How to configure Debian Apache log rotation. For more information, please follow other related articles on the PHP Chinese website!

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Docker uses Linux kernel features to provide an efficient and isolated application running environment. Its working principle is as follows: 1. The mirror is used as a read-only template, which contains everything you need to run the application; 2. The Union File System (UnionFS) stacks multiple file systems, only storing the differences, saving space and speeding up; 3. The daemon manages the mirrors and containers, and the client uses them for interaction; 4. Namespaces and cgroups implement container isolation and resource limitations; 5. Multiple network modes support container interconnection. Only by understanding these core concepts can you better utilize Docker.

NGINX and Apache have their own advantages and disadvantages and are suitable for different scenarios. 1.NGINX is suitable for high concurrency and low resource consumption scenarios. 2. Apache is suitable for scenarios where complex configurations and rich modules are required. By comparing their core features, performance differences, and best practices, you can help you choose the server software that best suits your needs.

Apachebecamefamousduetoitsopen-sourcenature,modulardesign,andstrongcommunitysupport.1)Itsopen-sourcemodelandpermissiveApacheLicenseencouragedwidespreadadoption.2)Themodulararchitectureallowedforextensivecustomizationandadaptability.3)Avibrantcommunit

Docker uses container engines, mirror formats, storage drivers, network models, container orchestration tools, operating system virtualization, and container registry to support its containerization capabilities, providing lightweight, portable and automated application deployment and management.

How to define header files using Visual Studio Code? Create a header file and declare symbols in the header file using the .h or .hpp suffix name (such as classes, functions, variables) Compile the program using the #include directive to include the header file in the source file. The header file will be included and the declared symbols are available.

The Docker image hosting platform is used to manage and store Docker images, making it easy for developers and users to access and use prebuilt software environments. Common platforms include: Docker Hub: officially maintained by Docker and has a huge mirror library. GitHub Container Registry: Integrates the GitHub ecosystem. Google Container Registry: Hosted by Google Cloud Platform. Amazon Elastic Container Registry: Hosted by AWS. Quay.io: By Red Hat

macvlan in Docker is a Linux kernel module that allows containers to have their own MAC address, enabling network isolation, performance improvement and direct interaction with the physical network. Using macvlan requires: 1. Install the kernel module; 2. Create a macvlan network; 3. Assign IP address segments; 4. Specify the macvlan network when container creation; 5. Verify the connection.

Docker logs are usually stored in the /var/log directory of the container. To access the log file directly, you need to use the docker inspect command to get the log file path, and then use the cat command to view it. You can also use the docker logs command to view the logs and add the -f flag to continuously receive the logs. When creating a container, you can use the --log-opt flag to specify a custom log path. In addition, logging can be recorded using the log driver, LogAgent, or stdout/stderr.
