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

How to record logs on Apache server

(*-*)浩
(*-*)浩Original
2019-11-27 15:09:292983browse

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/>

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/>

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/>

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/>

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/>

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:
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