1 http {2 3Log_format Main'$remote _addr-$remote _user [$time _local] "$request"'4 '$status $body _bytes_sent "$http _referer"'5 '"$http _user_agent" "$http _x_forwarded_for" "$request _time" "$upstream _response_time" "$upstream _cache_status" ';6 7 }8 9 description of the log variable explanation:Ten One $remote _addr: With $http_x_forwarded_for used to record the IP address of the client; A - $remote _user: Used to record the client user name; - the $time _local: Used to record access time and time zone; - - $request: The URL used to record the request and the HTTP protocol; - + $status: Used to record the status of the request; - + $body _bytes_sent: Record the size of the principal content sent to the client file; A at $http _referer: Used to record from that page link access; - - $http _user_agent: Log information about the client browser; - - $http _x_forwarded_for: It represents the client, which is the real IP on the request side of HTTP, which is added only when the HTTP proxy or Load balancer server is passed; - in $request _time: Refers to the time from accepting the first byte of the user request to sending the response data, including the time of receiving the request data, the program response time, and the output response data time; - to$upstream _response_time: Refers to the back end of the Nginx (php-CGI) establishes the time at which the connection begins until the data is accepted and then closed. +$upstream _cache_status: This variable to show the state of the cache, hit hits, in order to be able to count the cache hit rate, we need to record this state in the log
$upstream _cache_status contains the following states:
· MISS miss, request is routed to backend
· Hit Cache Hits
· EXPIRED Cache has expired request sent to backend
· UPDATING is updating the cache and will use the old answer
· STALE back end will get an expired reply
Statistical method: Divide the number of hits by the total log amount to get the cache hit rate:
' {if ($NF = = "\" hit\ "") hit++} END {printf "%.2f%", Hit/nr} ' access. Log
Nginx log Format