Home > Operation and Maintenance > Nginx > How to set the access_log format of nginx

How to set the access_log format of nginx

WBOY
Release: 2023-05-12 13:25:13
forward
1859 people have browsed it

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

Common variables:

## $request_timeRequest processing time, unit is seconds, decimal form$ upstream_addrCluster polling address##$upstream_response_time$remote_user$request $http_user_agent##$http_host $host
##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)







refers to the time from when Nginx establishes a connection to the backend (php-cgi) to when it accepts data and closes the connection



is used to record the client user name



Request method (GET or POST, etc.) URL (including $request_method, $host, $request_uri)



User browser identifier



The host of the requested url address (target url address)



Equivalent to $http_host


##$http_referer

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


$uri

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!

Related labels:
source:yisu.com
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template