Home >Backend Development >PHP Tutorial >Linux Notes (67) - Detailed explanation of nginx log files

Linux Notes (67) - Detailed explanation of nginx log files

WBOY
WBOYOriginal
2016-07-29 08:57:20912browse

  • Log file format
  • Log file cutting
    • Manual cutting
    • Automatic cutting

Log file format

Open nginx default configuration file nginx.conf

Linux Notes (67) - Detailed explanation of nginx log files

us Use the log_format directive to specify the format of the log file. Everything starting with $ is a variable. The meaning of these variables is as follows:

  1. $remote_addr and $http_x_forwarded_for are used to record the client’s IP address;
  2. $remote_user: used to record Client user name;
  3. $time_local: used to record access time and time zone;
  4. $request: used to record the URL and http protocol of the request;
  5. $status: used to record the request status; success is 200,
  6. $body_bytes_s ent: records the size of the body content of the file sent to the client;
  7. $http_referer: used to record the link accessed from that page;
  8. $http_user_agent: records relevant information of the client browser;

Then we pass access_log directive to specify the location of the log file

The variables in the red box in the above picture can be defined by yourself

If you want the above configuration to work, remove the # sign in front

If you want to turn off the log function, use access_log off

log file Cutting

In order to facilitate management, we often need to separate the logs according to time, such as one log file per day, so what should we do?

Manual cutting

Enter the logs directory and rename access.log

<code>mv access.<span>log</span><span>2016</span>-<span>3</span>-<span>4</span>.<span>log</span></code>

After renaming, nginx cannot find the log file, so we use the kill command to pass a signal to the main process of nginx and let it restart Log

Check the official document and find the signal to reopen the log

Linux Notes (67) - Detailed explanation of nginx log files

Use the kill command

Linux Notes (67) - Detailed explanation of nginx log files

Then nginx will reopen the log

Automatic cutting

We can write the above operation into a script, and then Use crontab to execute this script on time every day for log cutting, then automatic cutting will be completed.

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces Linux Notes (67) - Detailed explanation of nginx log files, including relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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