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

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

Jul 29, 2016 am 08:57 AM
access http log nginx

  • 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>
Copy after login

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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to convert deepseek pdf How to convert deepseek pdf Feb 19, 2025 pm 05:24 PM

DeepSeek cannot convert files directly to PDF. Depending on the file type, you can use different methods: Common documents (Word, Excel, PowerPoint): Use Microsoft Office, LibreOffice and other software to export as PDF. Image: Save as PDF using image viewer or image processing software. Web pages: Use the browser's "Print into PDF" function or the dedicated web page to PDF tool. Uncommon formats: Find the right converter and convert it to PDF. It is crucial to choose the right tools and develop a plan based on the actual situation.

How to read dbf file in oracle How to read dbf file in oracle May 10, 2024 am 01:27 AM

Oracle can read dbf files through the following steps: create an external table and reference the dbf file; query the external table to retrieve data; import the data into the Oracle table.

How to implement HTTP streaming using C++? How to implement HTTP streaming using C++? May 31, 2024 am 11:06 AM

How to implement HTTP streaming in C++? Create an SSL stream socket using Boost.Asio and the asiohttps client library. Connect to the server and send an HTTP request. Receive HTTP response headers and print them. Receives the HTTP response body and prints it.

WordPress site file access is restricted: Why is my .txt file not accessible through domain name? WordPress site file access is restricted: Why is my .txt file not accessible through domain name? Apr 01, 2025 pm 03:00 PM

Wordpress site file access is restricted: troubleshooting the reason why .txt file cannot be accessed recently. Some users encountered a problem when configuring the mini program business domain name: �...

How to implement HTTP file upload security using Golang? How to implement HTTP file upload security using Golang? Jun 01, 2024 pm 02:45 PM

Implementing HTTP file upload security in Golang requires following these steps: Verify file type. Limit file size. Detect viruses and malware. Store files securely.

How to make PHP5.6 and PHP7 coexist through Nginx configuration on the same server? How to make PHP5.6 and PHP7 coexist through Nginx configuration on the same server? Apr 01, 2025 pm 03:15 PM

Running multiple PHP versions simultaneously in the same system is a common requirement, especially when different projects depend on different versions of PHP. How to be on the same...

How to solve the problem of third-party interface returning 403 in Node.js environment? How to solve the problem of third-party interface returning 403 in Node.js environment? Mar 31, 2025 pm 11:27 PM

Solve the problem of third-party interface returning 403 in Node.js environment. When we use Node.js to call third-party interfaces, we sometimes encounter an error of 403 from the interface returning 403...

How to run the h5 project How to run the h5 project Apr 06, 2025 pm 12:21 PM

Running the H5 project requires the following steps: installing necessary tools such as web server, Node.js, development tools, etc. Build a development environment, create project folders, initialize projects, and write code. Start the development server and run the command using the command line. Preview the project in your browser and enter the development server URL. Publish projects, optimize code, deploy projects, and set up web server configuration.

See all articles