Home > Article > Operation and Maintenance > How to set the access_log format of nginx
Nginx access logs can be set in custom formats to meet specific needs.
Example:
示例1 log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]' '$host "$request_uri" $status' '"$http_referer" "$http_user_agent"'; 示例2 log_format main '$remote_addr [$time_local] ' '$host "$request_uri" $status "$request"' '"$http_referer" "$http_user_agent" "$request_time"'; 若不配置log_format或者不在access_log配置中指定log_format,则默认格式为: '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent";
Common variables:
##Variable |
Description |
$time_local |
Local time in common log format; (server time) |
$remote_addr |
Client (user) IP address |
$ status |
Request status code, such as 200, 404, 301, 302, etc. |
$body_bytes_sent |
The number of bytes sent to the client, excluding the size of the response header |
$bytes_sent |
The total number of bytes sent to the client |
$request_length |
The length of the request (including request line, request header and request body) |
|
|
|
|
|
|
|
|
|
|
|
|
Source page, that is, which page to go to this page from. If you directly enter the URL in the browser to access it, the referer will be empty |
|
The current URI in the request (without request parameters, the parameters are located in $args), which is different from the value of $request_uri passed by the browser, which can Modify it through internal redirection or using the index directive. | |
$document_uri |
is equivalent to $uri |
$request_uri |
has more parameters than $uri, that is, $uri $args |
$http_x_forwarded_for |
If a proxy is used, this parameter will record the ip of the proxy server and the ip of the client |
The above is the detailed content of How to set the access_log format of nginx. For more information, please follow other related articles on the PHP Chinese website!