Log_format is used to set the log record format: log_formatnameformatname indicates the format name and format indicates the same type. Log_format has a default combined log format, which is equivalent to apache's combined log format, as shown below: log_formatcombined '$ remo
Log_format is used to set the log record format:
Log_format name format
Name indicates the format name, and format indicates the equivalent format. Log_format has a default combined log format, which is equivalent to apache combined log format, as shown below:
Log_format combined '$ remote_addr-$ remote_user [$ time_local]'
'"$ Request" $ status $ body_bytes_sent'
'"$ Http_referer" "$ http_user_agent "';
If nginx is in the server load balancer, squid, and nginx Reverse proxy, the web server cannot directly obtain the real IP address of the client. $ Remote_addr: obtain the IP address of the reverse proxy. The reverse proxy server adds X-Forwarded-For information in the http header of the Forwarded request to record the client IP address and the server address of the client request. As follows:
Log_format porxy '$ http_x_forwarded_for-$ remote_user [$ time_local]'
'"$ Request" $ status $ body_bytes_sent'
'"$ Http_referer" "$ http_user_agent "';
The parameter annotations are as follows:
$ Remote_addr, $ http_x_forwarded_for record the client IP address
$ Remote_user record the client user name
$ Time_local records the access time
$ Request records the request URL and HTTP protocol
$ Status records the request status
$ Body_bytes_sent record size of the file sent to the client
$ Http_referer records the access from which page link
$ Http_user_agent: Record client browser information
Access_log is used to specify the log file path:
Access_log path [format [buffer = size | off]
Buffer sets the size of the memory cache area.
No logs:
Access_log off;
Use the default combined format to record logs:
Access_log logs/access. log or access_log logs/access. log combined;
Use the custom log format:
Access_log logs/access. log proxy buffer = 32 k;
Each server_name corresponds to one log file:
Access_log logs/$ server_name.log combined;
The log file contains variables. pay attention to the following issues:
Buffer is not used
For each log record, the file is opened first, then the log is written, and then disabled. You can use open_log_file_cache to set the log file cache (off by default). The format is as follows:
Open_log_file_cache max = n [inactive = time] [min_uses = n] [valid = time] | off
The parameter annotations are as follows:
Max: sets the maximum number of file descriptors in the cache. the LRU algorithm is used.
Inactive: Set the survival time. the default value is 10 s.
Min_uses: sets the minimum number of log files used, and the log file descriptor is recorded in the cache. the default value is 1.
Valid: sets the check frequency. the default value is 60 s.