Nginx server Log related instructions are mainly two, one is Log_format, used to set the log format,
Another is access_log, used to specify the log file storage path, format and cache size, generally in the Nginx configuration file in the diary configuration (/usr/local/nginx/conf/nginx.conf).
Nginx Log_format has a number of optional parameters to indicate the active state of the server, by default:
Log_format access ' $remote _addr-$remote _user [$time _local] "$request"
' $status $body _bytes_sent ' $http _referer '
' "$http _user_agent" "$http _x_forwarded_for";
To record more detailed information you need to set the Log_format, the specific parameters to set the format and description as follows:
Parameters |
Description |
Example |
$remote _addr |
Client Address |
211.28.65.253 |
$remote _user |
Client User Name |
-- |
$time _local |
Access time and time zone |
18/jul/2012:17:00:01 +0800 |
$request |
URI and HTTP protocol for the request |
"Get/article-10000.html http/1.1" |
$http _host |
Request address, which is the address (IP or domain name) you entered in the browser |
Www.it300.com 192.168.100.100 |
$status |
HTTP request Status |
200 |
$upstream _status |
Upstream status |
200 |
$body _bytes_sent |
Send to client file content size |
1547 |
$http _referer |
URL Jump Source |
https://www.baidu.com/ |
$http _user_agent |
User Terminal browser and other information |
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; trident/4.0; SV1; GTB7.0;. net4.0c; |
$ssl _protocol |
SSL protocol version |
TLSv1 |
$ssl _cipher |
Algorithms in the exchange of data |
Rc4-sha |
$upstream _addr |
The address of the backend upstream, which is the host address that really provides the service |
10.10.10.100:80 |
$request _time |
Total time for the entire request |
0.205 |
$upstream _response_time |
Upstream response time during the request |
0.002 |
Examples are as follows:
1. Configuration files
1 |
#vim /usr/local/nginx/conf/nginx.conf |
2 |
log_format access ‘$remote_addr - $remote_user [$time_local] "$request" ‘ |
3 |
‘$status $body_bytes_sent "$http_referer" ‘ |
4 |
‘"$http_user_agent" $http_x_forwarded_for ‘ |
5 |
‘"$upstream_addr" "$upstream_status" "$upstream_response_time" "$request_time"‘ ; |
6 |
include /usr/local/nginx/conf/vhost/*.conf; |
Log_format setting the log format for Nginx