Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the relevant configurations of Nginx logs?

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "what are the relevant configurations of Nginx logs". The editor shows you the operation process through actual cases, and the operation method is simple, fast and practical. I hope this article "what are the relevant configurations of Nginx logs" can help you solve the problem.

There are two related configurations for Nginx logs: access_log and log_format.

Default format: access_log / data/logs/nginx-access.log;log_format old'$remote_addr [$time_local] $status $request_time $body_bytes_sent''"$request"$http_referer"$http_user_agent"'

It is believed that most people who have used Nginx are familiar with the default Nginx log format configuration and the contents of the log. However, the default configuration and format are readable, but difficult to calculate.

Policies related to Nginx log flushing can be configured:

For example, set buffer,buffer over 32k before flushing; if buffer is not satisfied with the 5s clock, the configuration for forced flushing is as follows:

Access_log / data/logs/nginx-access.log buffer=32k flush=5s

This determines whether to see the log in real time and the impact of the log on the disk IO.

There are many variables that the Nginx log can record that do not appear in the default configuration:

For example:

Request data size: $request_length return data size: $bytes_sent request time: $request_time connection serial number: $connection number of current connection requests: $connection_requests

The default format of Nginx cannot be calculated, and you need to find a way to convert it to a computable format, such as splitting each field with the control character ^ A (typed out by ctrl+v ctrl+a under Mac).

The format of log_format can be as follows:

Log_format new'$remote_ addr ^ A $http_x_forwarded_ for ^ A $host ^ A $time_ local ^ A $status ^ A'$request_ time ^ A $request_ time ^ A $bytes_ sentinel A $http_ referer ^ A $request ^ A $http_user_agent'; is then analyzed through the common Linux command line tools:

Find the most frequently visited URL and times:

Cat access.log | awk-F'^ A''{print $10}'| sort | uniq-c

Find the wrong access to the current log file 500:

Cat access.log | awk-F'^ A''{if ($5 = = 500) print $0}'

Find the number of current log file 500 errors:

Cat access.log | awk-F'^ A''{if ($5 = = 500) print $0}'| wc-l

Find the number of 500 error visits in a minute:

Cat access.log | awk-F'^ A''{if ($5 = = 500) print $0}'| grep '09print 00' | wc-l

Find slow requests that take more than 1 second:

Tail-f access.log | awk-F'^ A'{if ($6 > 1) print $0}'

If you only want to view certain bits:

Tail-f access.log | awk-F'^ A''{if ($6 > 1) print $3 "|" $4}'

Find the URL with the most 502 errors:

Cat access.log | awk-F'^ A' {if ($5 million) print $11}'| sort | uniq-c

Find 200 blank pages

Cat access.log | awk-F'^ A' {if ($5 million $200 & & $8 print $3 "|" $4 "|" $11 "|" $6} "

View real-time log data streams

Tail-f access.log | cat-e

Or

Tail-f access.log | tr'^ A'| 'what are the relevant configurations of Nginx logs?' that's all for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report