Home Operation and Maintenance Apache How to record logs on Apache server

How to record logs on Apache server

Nov 27, 2019 pm 03:09 PM
apache

How to record logs on Apache server

#Apache server logs provide detailed information that helps detect common problems with the server. To log access to a website, mod_log_configmodule must be enabled.

There are three instructions in the apache configuration file, namely -

TransferLog: Create a log file. (Recommended learning: Apache server)

LogFormat: Specify a custom format.

CustomLog: Create and format log files.

The TransferLog directive is available in the apache configuration file, which rotates the virtual host log files according to the set parameters.

VirtualHost www.example.com><br/><br/>  ServerAdmin webmaster@yiibai.com<br/>  DocumentRoot /usr/www/example/httpd/htdocs/<br/>  ServerName www.example.com<br/>  ServerAlias example.com www.example<br/>  ErrorLog /usr/www/example/httpd/logs/error_log<br/>  TransferLog /usr/www/example/httpd/logs/accesslog<br/>  CustomLog /usr/www/example/httpd/logs/accesslog combined<br/><br/></VirtualHost><br/>
Copy after login

Two types of Apache log formats

Common log format

Combined log format

They can be enabled by editing the apache configuration file, which is the apache2.conf (Debian/ubuntu) or httpd.conf (rpm-based systems) file.

General log format

LogFormat "%h %l %u %t \"%r\" %>s %b" common<br/>CustomLog logs/access_log.log common<br/>
Copy after login

The general log content examples generated by Apache are as follows

[Wed Oct 11 14:32:52 2000] [error] [client 127.0.0.1] client denied by server configuration: /export/home/live/ap/htdocs/test<br/>
Copy after login

Combined log format

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined<br/>CustomLog log/access_log.log combined<br/>
Copy after login

In the above format,

%h is the remote host

%l is the identity of the user determined by identd

%u is the user determined by HTTP authentication Name

%t is the time it took for the server to finish processing the request.

%r is the request line from the client ("GET/HTTP/1.0").

%> s is the status code sent from the server to the client (500, 404, etc.)

%b is the size of the client response (in bytes) Referer is the link to this URL page.

The user agent is the browser identification string.

Combined logs generated by Apache:

199.180.11.91 - - [06/Mar/2019:04:22:58 +0100] "GET /robots.txt HTTP/1.1" 404 1228 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)"<br/>
Copy after login

Custom logs create separate log files for each virtual host on the server. It needs to be specified in the virtual host section of the configuration file.

You can see the virtual host configuration mentioned below, the generated log will be customized for that virtual host, and the format will be combined.

How to record logs on Apache server

The above is the detailed content of How to record logs on Apache server. 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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months 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)

How to run the h5 project How to run the h5 project Apr 06, 2025 pm 12:21 PM

Running the H5 project requires the following steps: installing necessary tools such as web server, Node.js, development tools, etc. Build a development environment, create project folders, initialize projects, and write code. Start the development server and run the command using the command line. Preview the project in your browser and enter the development server URL. Publish projects, optimize code, deploy projects, and set up web server configuration.

How to export pdf with xml How to export pdf with xml Apr 03, 2025 am 06:45 AM

There are two ways to export XML to PDF: using XSLT and using XML data binding libraries. XSLT: Create an XSLT stylesheet, specify the PDF format to convert XML data using the XSLT processor. XML Data binding library: Import XML Data binding library Create PDF Document object loading XML data export PDF files. Which method is better for PDF files depends on the requirements. XSLT provides flexibility, while the data binding library is simple to implement; for simple conversions, the data binding library is better, and for complex conversions, XSLT is more suitable.

Apache Troubleshooting: Diagnosing & Resolving Common Errors Apache Troubleshooting: Diagnosing & Resolving Common Errors Apr 03, 2025 am 12:07 AM

Apache errors can be diagnosed and resolved by viewing log files. 1) View the error.log file, 2) Use the grep command to filter errors in specific domain names, 3) Clean the log files regularly and optimize the configuration, 4) Use monitoring tools to monitor and alert in real time. Through these steps, Apache errors can be effectively diagnosed and resolved.

How to generate pom.xml How to generate pom.xml Apr 03, 2025 am 06:00 AM

There are the following ways to generate a pom.xml file: Use Maven Archetype to provide predefined project templates to automatically generate pom.xml files for specific types of projects. Use the Maven Helper plugin to provide commands to generate pom.xml files. Create manually to customize the pom.xml file for the project.

How to set character encoding on the server side to solve Bootstrap Table garbled How to set character encoding on the server side to solve Bootstrap Table garbled Apr 07, 2025 pm 12:00 PM

To set character encoding on the server side to solve the garbled Bootstrap Table, you need to follow the following steps: check the server character encoding; edit the server configuration file; set the character encoding to UTF-8; save and restart the server; verify the encoding.

Cannot start mysql in xampp Cannot start mysql in xampp Apr 08, 2025 pm 03:15 PM

There are many reasons why XAMPP fails to start MySQL, including port conflicts, configuration file errors, insufficient system permissions, service dependency issues, and installation issues. The troubleshooting steps are as follows: 1) Check port conflicts; 2) Check configuration files; 3) Check system permissions; 4) Check service dependencies; 5) Reinstall MySQL. Follow these steps and you can find and resolve issues that cause MySQL startup to fail.

How to preview the Bootstrap page How to preview the Bootstrap page Apr 07, 2025 am 10:06 AM

The preview methods of Bootstrap pages are: open the HTML file directly in the browser; automatically refresh the browser using the Live Server plug-in; and build a local server to simulate an online environment.

PDF to XML: Best practices for preserving formats and data PDF to XML: Best practices for preserving formats and data Apr 02, 2025 pm 11:18 PM

How to convert PDF to XML? Use an online converter, desktop software or programming library to select the appropriate file format (XHTML, PDF/UA, XML) to optimize PDF (OCR, delete unnecessary elements, adjust pages) to refine conversion settings (tag, metadata, image extraction) quality control (verification XML, manual inspection, adjustment) For complex conversions, use professional tools

See all articles