Messy log Nginx in daily use is mostly used as both a static resource server and a reverse proxy server. In particular, considering cross-domain issues, the same listening port is used for static resources and backend interfaces. If no filtering is performed, a large number of requests for static resources such as js, css, jpg, etc. will be seen in access_log, which will affect the viewing of backend interface call logs. I didn't pay much attention to this thing at first, but when I was browsing an article about Nginx optimization, I found a method to use map to define a parameter of whether to write logs. Combined with the recent use of map for dynamic cross-domain configuration, I simply learned and recorded another usage scenario of map. Use map to filter logs for accessing static resource files http { log_format main '$remote_addr [$time_local] $request $status ' 'uct="$upstream_connect_time" rt="$request_time"'; map $uri $not_static { default 1; ~^(.*\.(gif|jpg|jpeg|png|bmp|swf|js|css|woff|ttf)$) 0; } server { listen 23456; server_name localhost; access_log logs/test.log main if=$not_static; } } Explanation:
Another way to write dynamic and static separated logs location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css|woff|ttf)$ { #access_log off; #Do not output the log of access to static resources access_log logs/static_resources.log; } This is the end of this article about the implementation of Nginx access log filtering of static resource files. For more relevant Nginx access log content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Vue uses the video tag to implement video playback
>>: MySQL uses the truncate command to quickly clear all tables in a database
First, what is database partitioning? I wrote an ...
This article shares the specific code of the canv...
Table of contents Some basic configuration About ...
Windows 10 1903 is the latest version of the Wind...
Table of contents Usage scenarios Solution 1. Use...
As an entry-level Linux user, I have used simple ...
Nginx logs can be used to analyze user address lo...
To set the line spacing of <p></p>, us...
This article shares the specific code of the vue3...
HTML: Title Heading is defined by tags such as &l...
【SQL】SQL paging query summary The need for paging...
background Last week the company trained on MySQL...
If you want to exit bash, there are two options: ...
Table of contents Create a global shared content ...
Table of contents 1. New II. Modification element...