当前位置:网站首页>Apache server access log access Log settings
Apache server access log access Log settings
2022-07-04 12:56:00 【Brother Xing plays with the clouds】
One 、 Access log information
When the browser requests The server when , If in The server Access logs are set on , The user's access records will be recorded .
For example, I visit local apache A default log generated :
127.0.0.1 - - [03/Feb/2015:23:14:24 +0800] "GET / HTTP/1.1" 200 2
It is divided into 7 Parts of
(1) The first information is the address of the remote host , That is, it shows who is visiting the website .( You can ask for apache Find out all the host names , And use the host name in the log file to replace IP Address , But this practice will have a great impact The server The speed of logging , Thus reducing the efficiency of the entire website , It's not worth recommending ). However , If it is really necessary to let Apac
e Find the name of the remote host , You can use the following instructions :
HostNameLookups on
If HostNameLookups Set to double instead of on, The logger will reverse the hostname it finds , Verify that the host name does point to the original IP Address .
(2) The second item of the log record in the above example is blank , Use one “-” Placeholder replacement . In fact, this is the case most of the time . This location is used to record the identity of the browser , This is not just the login name of the browser , It's the browser's email Address or other unique identifier . This information is provided by identd return , Or return directly from the browser .( In order to avoid users' mailbox being harassed by spam , The second is to use “-” To replace the ).
(3) The third item in the diary is also blank . This location is used to record the name provided by the browser when authenticating . Of course , If some content of the website requires users to authenticate , Then this information room will not be empty . however , For most websites , This item is still blank in most records of the log file .
(4) The fourth item of logging is the requested time . This information is enclosed in square brackets , And “ Common log format ” perhaps “ Standard English format ”. therefore , Time information last “-0400” Indicates that the time zone of the server is in UTC Previous 4 Hours .
(5) The fifth information recorded in the log is probably the most useful information in the whole log , It tells us what kind of request the server receives . The typical format of this information is “METHOD RESOURCE PROTOCOL” namely “ Method resources agreement ”( We usually monitor logs , It's mainly about this content ). In the example METHOD yes GET, also POST、HEAD Other types , Mainly these three .
RESOURCE It refers to the document or URL. In this case , What the browser requests is “/”, That is, the root or home page of the website . Most of the time ,“/” Point to DocumentRoot The directory index.html file , However, depending on the server configuration, it may also point to other files .
PROTOCOL Usually HTTP, Then add the version number .
(6) The sixth information room status code of the log . It tells us whether the request was successful , Or what kind of mistakes have you made . Most of the time this item is 200, It indicates that the server has successfully responded to the browser's request , Everything is all right .( With 2 The status code at the beginning indicates success , With 3 The status code at the beginning indicates that the user request has been redirected to another location for various reasons , With 4 The status code at the beginning indicates that there is some error on the client , With 5 The status code at the beginning indicates that the server has encountered an error ).
(7) The seventh entry in the log indicates the total number of bytes sent to the client . It tells us if the transmission is interrupted ( That is, whether the value is the same as the size of the file )
Two 、 Configure access logs
stay apache Configuration file for httpd.conf in , One line is configured like this :
CustomLog "logs/access.log" common
Specifies the directory path of the log ./logs/, Specifies the format of the log , Default common.
common The format is through :LogFormat "%h %l %u %t \"%r\" %>s %b" common Defined .
The format string in double quotation marks represents specific information .
apache Format string and its meaning :
%% Percent sign (Apache2.0.44 Or later ) %a Distal IP Address %A This machine IP Address %B except HTTP The number of bytes sent out of the header %b With CLF In addition to HTTP The number of bytes sent out of the header , That is to say, when there is no byte transfer, it will display '-' instead of 0. %{Foobar}C Sent to the server in the request cookieFoobar The content of . %D The time taken by the server to process this request , In micro units . %{FOOBAR}e environment variable FOOBAR Value %f file name %h Remote host %H The protocol requested to be used %{Foobar}i The request header sent to the server Foobar: The content of . %l Remote login ( from identd And come , If you support it ), Unless IdentityCheck Set to "On", Or you'll get a "-". %m Requested method %{Foobar}n Comments from another module Foobar The content of . %{Foobar}o Answer head Foobar: The content of . %p The server serves the standard port of the request . %P Of the subprocess serving this request PID. %{format}P The PID or TID( Threads ID),format The value range of is :pid and tid(2.0.46 And later versions ) as well as hextid( need APR1.2.0 And above ) %q Query string ( If there is one "?" guide , Otherwise, an empty string is returned ) %r First line of request %s state . For internal redirection requests , This state refers to the state of the original request ,---%>s The status of the last request . %t Time , In normal log time format ( Standard English format ) %{format}t Time , use strftime(3) Time in the specified format .( By default, in localized format ) %T Time taken to process the request , In seconds . %u Remote user name ( Based on verification information ; If you return status(%s) by 401, It could be a fake ) %U Requested URL route , Does not contain the query string . %v The standard for providing service to this request ServerName. %V according to UseCanonicalName The server name set by the command . </span><span style="font-size:18px;">
【 Add 】"<" and ">" The modifier can be used to specify whether to select the original request or the final request for the request that has been internally redirected . By default ,%s, %U, %T, %D, %r Use the original request , All other format strings choose the final request . for example ,<strong>%>s</strong> It can be used to record the final status of the request , and %<u Then record an original authenticated user who has been internally redirected to a request for non authenticated resources . If in “%” One or more... Are placed between and variables HTTP The status code , Only when the status code returned by the request belongs to one of the specified status codes , The contents represented by variables will be recorded . for example , If we want to record all the invalid links of the website , Then you can use : LogFormat %404{Referer}i BrokenLinks conversely , If we want to record requests whose status code is not equal to the specified value , Just add one “!” A symbol is enough : LogFormat %!200U SomethingWrong
We can also customize the log format , for example :
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" " combine
Defined combine Format among \"%{Referer}i\" \"%{User-Agent}i\" Is the plea header sent to the server and Referer link .
边栏推荐
- C fonctions linguistiques
- Master the use of auto analyze in data warehouse
- DGraph: 大规模动态图数据集
- 七、软件包管理
- 8个扩展子包!RecBole推出2.0!
- I want to talk about yesterday
- Langue C: trouver le nombre de palindromes dont 100 - 999 est un multiple de 7
- A taste of node JS (V), detailed explanation of express module
- VIM, another program may be editing the same file If this is the solution of the case
- Argminer: a pytorch package for processing, enhancing, training, and reasoning argument mining datasets
猜你喜欢
Fly tutorial 02 advanced functions of elevatedbutton (tutorial includes source code) (tutorial includes source code)
洞见科技解决方案总监薛婧:联邦学习助力数据要素安全流通
【AI系统前沿动态第40期】Hinton:我的深度学习生涯与研究心法;Google辟谣放弃TensorFlow;封神框架正式开源
分布式事务相关概念与理论
AI 绘画极简教程
C语言函数
Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
[data clustering] section 3 of Chapter 4: DBSCAN performance analysis, advantages and disadvantages, and parameter selection methods
Transformer principle and code elaboration (tensorflow)
【数据聚类】第四章第一节3:DBSCAN性能分析、优缺点和参数选择方法
随机推荐
C fonctions linguistiques
WPF double slider control and forced capture of mouse event focus
游戏启动后提示安装HMS Core,点击取消,未再次提示安装HMS Core(初始化失败返回907135003)
轻松玩转三子棋
数据库锁表?别慌,本文教你如何解决
Agile development / agile testing experience
【Android Kotlin】lambda的返回语句和匿名函数
Talk about "in C language"
使用 NSProxy 实现消息转发
使用Scrcpy投屏
Fundamentals of container technology
R language -- readr package reads and writes data
阿里云有奖体验:用PolarDB-X搭建一个高可用系统
0x15 string
Interviewer: what is the difference between redis expiration deletion strategy and memory obsolescence strategy?
Play Sanzi chess easily
干货整理!ERP在制造业的发展趋势如何,看这一篇就够了
CA:用于移动端的高效坐标注意力机制 | CVPR 2021
After the game starts, you will be prompted to install HMS core. Click Cancel, and you will not be prompted to install HMS core again (initialization failure returns 907135003)
分布式事务相关概念与理论