From 14289621856bd9883ec40873209afcc362ae9522 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 2 Jul 2024 11:15:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0nginx=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- used-settings.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/used-settings.md b/used-settings.md index 787977a..6056cc8 100644 --- a/used-settings.md +++ b/used-settings.md @@ -136,5 +136,24 @@ hostname ubuntu-1604 > 适用于 `Ubuntu 16.04` 和 `CentOS 7` 以上版本 +--- +#### Nginx 日志按天分隔 + +修改配置文件 + +``` +log_format main '$time_iso8601 - $remote_addr $remote_user "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + +map $time_iso8601 $logdate { + '~^(?\d{4}-\d{2}-\d{2})' $ymd; + default 'date-not-found'; +} + +access_log logs/access-$logdate.log main; +``` + +main 名称可以自定义修改,修改完执行 `nginx -t` 看下语法有没问题,没问题再执行 `nginx -s reload` 就可以了。