Home Operation and Maintenance Linux Operation and Maintenance How to configure Debian Apache log rotation

How to configure Debian Apache log rotation

Apr 13, 2025 am 09:15 AM
apache tool ai red

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
Copy after login

If not installed, execute:

 sudo apt-get update
sudo apt-get install logrotate
Copy after login

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
Copy after login

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
Copy after login

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>
Copy after login

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, the postrotate script is executed only once.
  • postrotate ... endscript : The script executed after log rotation, reload the Apache configuration here. (Use more general if [ -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
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Clair Obscur: Expedition 33 - How To Get Perfect Chroma Catalysts
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1677
14
PHP Tutorial
1278
29
C# Tutorial
1257
24
Best Practices for Writing JavaScript Code with VSCode Best Practices for Writing JavaScript Code with VSCode May 15, 2025 pm 09:45 PM

Best practices for writing JavaScript code in VSCode include: 1) Install Prettier, ESLint, and JavaScript (ES6) codesnippets extensions, 2) Configure launch.json files for debugging, and 3) Use modern JavaScript features and optimization loops to improve performance. With these settings and tricks, you can develop JavaScript code more efficiently in VSCode.

View Git history and changes in VSCode View Git history and changes in VSCode May 15, 2025 pm 09:24 PM

How to view Git history and changes in VSCode include: 1. Open VSCode and make sure the project has initialized the Git repository. 2. Click the "Source Code Management" icon in the left sidebar. 3. Select "...(more options)" and click "Git:ShowGitOutput". 4. View commit history and file changes. 5. Right-click the file and select "Git:ShowFileHistory" to view the file change history. Through these steps, you can efficiently view Git history and changes in VSCode to improve development efficiency.

Share the top ten correct address rankings of currency exchanges in 2025 Share the top ten correct address rankings of currency exchanges in 2025 May 15, 2025 pm 03:36 PM

​In the 2025 currency exchange rankings, the top ten exchanges attracted much attention for their security, liquidity, user experience and innovation.

What is encryption jump start (blockchain jump start)? What is encryption jump start (blockchain jump start)? May 15, 2025 pm 04:24 PM

What is encryption jump? How is encryption rush to take shape? How to avoid encryption jumping? The crypto field is a rush to make profits by unconfirmed transactions, leveraging the transparency of blockchain. Learn how traders, bots, and validators manipulate transaction sorting, their impact on decentralized finance, and possible ways to protect transactions. Below, the editor of Script Home will give you a detailed introduction to encryption and rush forward! What is the rush to the encryption field? Taking the lead has long been a problem in the financial market. It originated in the traditional financial field, and refers to brokers or insiders using privileged information to trade before clients. Such behavior is considered immoral and illegal, and the regulator will investigate and punish it.

An effective way to resolve Git commit conflicts in VSCode An effective way to resolve Git commit conflicts in VSCode May 15, 2025 pm 09:36 PM

Handling Git commit conflicts in VSCode can be effectively resolved through the following steps: 1. Identify the conflicting file, and VSCode will be highlighted in red. 2. Manually edit the code between conflict marks and decide to retain, delete or merge. 3. Keep branches small and focused to reduce conflicts. 4. Use GitLens extension to understand code history. 5. Use VSCode to build-in Git commands, such as gitmerge--abort or gitreset--hard. 6. Avoid relying on automatic merge tools and carefully check the merge results. 7. Delete all conflict marks to avoid compilation errors. With these methods and tricks, you can handle Git conflicts efficiently in VSCode.

Use VSCode to perform version fallback operation of code Use VSCode to perform version fallback operation of code May 15, 2025 pm 09:42 PM

In VSCode, you can use Git for code version fallback. 1. Use gitreset--hardHEAD~1 to fall back to the previous version. 2. Use gitreset--hard to fall back to a specific commit. 3. Use gitrevert to safely fall back without changing history.

A complete list of websites that can watch the market for free Free websites that can watch the market for currency circle A complete list of websites that can watch the market for free Free websites that can watch the market for currency circle May 15, 2025 pm 03:27 PM

Investors and traders can view cryptocurrency markets for free, including Ouyi, Binance, Huobi and Sesame Open. 1. Visit Ouyi’s official website and navigate to “Quotes” to view real-time data. 2. Visit Binance official website and click "Quotes" to view real-time data and analysis tools. 3. Visit Huobi’s official website and navigate to “Quotes” to view real-time data. 4. Visit the official website of Sesame Open Door to view the market data directly

What are the income stablecoins? 20 types of income stablecoins What are the income stablecoins? 20 types of income stablecoins May 15, 2025 pm 06:06 PM

If users want to pursue profit maximization, they can maximize the value of the stablecoin through profit-based stablecoins. Earnings stablecoins are assets that generate returns through DeFi activities, derivatives strategies or RWA investments. Currently, this type of stablecoins accounts for 6% of the market value of the US$240 billion stablecoins. As demand grows, JPMorgan believes that the proportion of 50% is not out of reach. Income stablecoins are minted by depositing collateral into an agreement. The deposited funds are used to invest in the income strategy, and the income is shared by the holder. It's like a traditional bank lending out the funds deposited and sharing interest with depositors, except that the interest rate of the income stablecoin is higher

See all articles