nginx access.log log adjustment

There are two main nginx log related instructions, one is log_format, which is used to set the log format, and the other is access_log, which is used to specify the storage path, format and cache size of log files. The popular understanding is to use log_format to define what you want to use first. log format, and then follow the defined log_format when using access_log to define a virtual host or global log; in fact, this is in the default configuration file, and you can open it. As follows:

    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log logs/access.log main;
Let's talk about the meaning of the variables in these logs. In fact, you can guess the name by looking at it.

$remote_addr / $http_x_forwarded_for is used to record the ip address of the client;

$remote_user is used to record the client user name;

$time_local is used to record the access time and time zone;

$request is used to record the requested url and http protocol;

$status is used to record Request status, success is 200;

$body_bytes_sent records the content size of the file body sent to the client;

$http_referer is used to record the access from that page link;

$http_user_agent records the relevant information of the client browser;

usually the web server is placed behind the reverse proxy, so that the client's IP address cannot be obtained, and it is obtained through $remote_addr The IP address that arrives is the IP address of the reverse proxy server. The reverse proxy server can add x_forwarded_for information to the http header information of the forwarding request to record the IP address of the original client and the server address of the original client's request; in fact, in the new version of nginx, the default is There is such a thing. x_forwarded_for

uses the access_log command to store the log file path. After setting the log format

with the log_format command, you need to use the access_log command to specify the log file storage path. Such as the following example:

    #access_log logs/access.log main;
If you do not want to enable the log, use:

   access_log off ;
When defining the log directory, it should be noted that the user and group set by the nginx process must have the ability to create files in this path Permissions, assuming that the user name and user group set by the usr directive of nginx are both www, and the user name and group of the logs directory are root, then the log file will not be created.

http://blog.sina.com.cn/s/blog_9bd573450101iqdc.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326397483&siteId=291194637