From ce191adfd8dfec5465c77916adfd598803f5919e Mon Sep 17 00:00:00 2001 From: augushong Date: Tue, 28 Jul 2026 00:20:32 +0800 Subject: [PATCH] =?UTF-8?q?feat(nginx-log):=204=20=E4=B8=AA=20stack=20?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E5=A2=9E=E5=8A=A0=20log=5Fformat=20=E4=B8=8E?= =?UTF-8?q?=20access=5Flog=20=E9=85=8D=E7=BD=AE=EF=BC=88Docker=20=E5=BC=80?= =?UTF-8?q?=E7=AE=B1=E5=8D=B3=E7=94=A8=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/adminInitData/SystemMenu.php | 44 +++++++++++++++++++ .../source/docker/nginx-log-format.conf | 6 +++ .../docker-dev-sync/source/docker/nginx.conf | 3 ++ .../docker-dev-sync/source/docker/run.sh | 6 +++ .../source/docker/nginx-log-format.conf | 6 +++ .../stack/docker-dev/source/docker/nginx.conf | 3 ++ source/stack/docker-dev/source/docker/run.sh | 7 +++ .../source/docker/nginx-log-format.conf | 6 +++ .../docker-serve/source/docker/nginx.conf | 3 ++ .../stack/docker-serve/source/docker/run.sh | 7 +++ .../full/source/docker/nginx-log-format.conf | 6 +++ source/stack/full/source/docker/nginx.conf | 3 ++ source/stack/full/source/docker/run.sh | 7 +++ 13 files changed, 107 insertions(+) create mode 100644 source/stack/docker-dev-sync/source/docker/nginx-log-format.conf create mode 100644 source/stack/docker-dev/source/docker/nginx-log-format.conf create mode 100644 source/stack/docker-serve/source/docker/nginx-log-format.conf create mode 100644 source/stack/full/source/docker/nginx-log-format.conf diff --git a/extend/base/admin/service/adminInitData/SystemMenu.php b/extend/base/admin/service/adminInitData/SystemMenu.php index 6a26cab..db39412 100644 --- a/extend/base/admin/service/adminInitData/SystemMenu.php +++ b/extend/base/admin/service/adminInitData/SystemMenu.php @@ -209,6 +209,50 @@ $ul_system_menu = array( "sort" => 0, "status" => 1, ), + array( + "id" => 300, + "pid" => 0, + "title" => "Nginx 日志分析", + "icon" => "fa fa-chart-bar", + "href" => "", + "params" => "", + "target" => "_self", + "sort" => 0, + "status" => 1, + ), + array( + "id" => 301, + "pid" => 300, + "title" => "访问统计仪表盘", + "icon" => "fa fa-line-chart", + "href" => "system.nginx_log_stat/index", + "params" => "", + "target" => "_self", + "sort" => 0, + "status" => 1, + ), + array( + "id" => 302, + "pid" => 300, + "title" => "原始访问日志", + "icon" => "fa fa-file-text", + "href" => "system.nginx_access_log/index", + "params" => "", + "target" => "_self", + "sort" => 0, + "status" => 1, + ), + array( + "id" => 303, + "pid" => 300, + "title" => "读取位置管理", + "icon" => "fa fa-map-marker", + "href" => "system.nginx_log_position/index", + "params" => "", + "target" => "_self", + "sort" => 0, + "status" => 1, + ), ); diff --git a/source/stack/docker-dev-sync/source/docker/nginx-log-format.conf b/source/stack/docker-dev-sync/source/docker/nginx-log-format.conf new file mode 100644 index 0000000..b7fc334 --- /dev/null +++ b/source/stack/docker-dev-sync/source/docker/nginx-log-format.conf @@ -0,0 +1,6 @@ +# ulthon_admin nginx_log 分析专用 log_format +# 必须放在 nginx 的 http 块(通过 conf.d/*.conf 自动 include) +log_format analytics '$remote_addr - $remote_user [$time_local] ' + '"$request" $status $body_bytes_sent ' + '"$http_referer" "$http_user_agent" ' + '$request_time $upstream_response_time $bytes_sent'; diff --git a/source/stack/docker-dev-sync/source/docker/nginx.conf b/source/stack/docker-dev-sync/source/docker/nginx.conf index 801249e..8f100ba 100644 --- a/source/stack/docker-dev-sync/source/docker/nginx.conf +++ b/source/stack/docker-dev-sync/source/docker/nginx.conf @@ -14,6 +14,9 @@ server { # 运行时长不限制 fastcgi_read_timeout 60000; + # ulthon_admin nginx_log 分析:access_log 写到 runtime(持久化 + PHP 必能读) + access_log /var/www/html/runtime/nginx/access.log analytics; + location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; diff --git a/source/stack/docker-dev-sync/source/docker/run.sh b/source/stack/docker-dev-sync/source/docker/run.sh index 8b32241..c7b424b 100644 --- a/source/stack/docker-dev-sync/source/docker/run.sh +++ b/source/stack/docker-dev-sync/source/docker/run.sh @@ -50,6 +50,12 @@ mkdir -p /var/www/html/public/build && chmod -R 777 /var/www/html/public/build mkdir -p /var/www/html/storage && chmod -R 777 /var/www/html/storage mkdir -p /var/www/html/memoryspace && chown -R www-data:www-data /var/www/html/memoryspace +# 复制 nginx_log 分析的 log_format 配置到 nginx http 块(conf.d 自动 include) +cp "$SCRIPT_DIR/nginx-log-format.conf" /etc/nginx/conf.d/ + +# 创建 nginx access_log 目录(必须在 service nginx start 之前) +mkdir -p /var/www/html/runtime/nginx && chmod 777 /var/www/html/runtime/nginx + # ---- Step 4: Output parameters and start services ---- echo "参数为:$@" diff --git a/source/stack/docker-dev/source/docker/nginx-log-format.conf b/source/stack/docker-dev/source/docker/nginx-log-format.conf new file mode 100644 index 0000000..b7fc334 --- /dev/null +++ b/source/stack/docker-dev/source/docker/nginx-log-format.conf @@ -0,0 +1,6 @@ +# ulthon_admin nginx_log 分析专用 log_format +# 必须放在 nginx 的 http 块(通过 conf.d/*.conf 自动 include) +log_format analytics '$remote_addr - $remote_user [$time_local] ' + '"$request" $status $body_bytes_sent ' + '"$http_referer" "$http_user_agent" ' + '$request_time $upstream_response_time $bytes_sent'; diff --git a/source/stack/docker-dev/source/docker/nginx.conf b/source/stack/docker-dev/source/docker/nginx.conf index 801249e..8f100ba 100644 --- a/source/stack/docker-dev/source/docker/nginx.conf +++ b/source/stack/docker-dev/source/docker/nginx.conf @@ -14,6 +14,9 @@ server { # 运行时长不限制 fastcgi_read_timeout 60000; + # ulthon_admin nginx_log 分析:access_log 写到 runtime(持久化 + PHP 必能读) + access_log /var/www/html/runtime/nginx/access.log analytics; + location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; diff --git a/source/stack/docker-dev/source/docker/run.sh b/source/stack/docker-dev/source/docker/run.sh index 21d57a6..e900734 100644 --- a/source/stack/docker-dev/source/docker/run.sh +++ b/source/stack/docker-dev/source/docker/run.sh @@ -24,6 +24,13 @@ mkdir -p /var/www/html/storage && chmod -R 777 /var/www/html/storage mkdir -p /var/www/html/memoryspace && chown -R www-data:www-data /var/www/html/memoryspace +# 复制 nginx_log 分析的 log_format 配置到 nginx http 块(conf.d 自动 include) +cp "$SCRIPT_DIR/nginx-log-format.conf" /etc/nginx/conf.d/ + +# 创建 nginx access_log 目录(必须在 service nginx start 之前) +mkdir -p /var/www/html/runtime/nginx && chmod 777 /var/www/html/runtime/nginx + + # 运行redis # nohup redis-server --requirepass "" & diff --git a/source/stack/docker-serve/source/docker/nginx-log-format.conf b/source/stack/docker-serve/source/docker/nginx-log-format.conf new file mode 100644 index 0000000..b7fc334 --- /dev/null +++ b/source/stack/docker-serve/source/docker/nginx-log-format.conf @@ -0,0 +1,6 @@ +# ulthon_admin nginx_log 分析专用 log_format +# 必须放在 nginx 的 http 块(通过 conf.d/*.conf 自动 include) +log_format analytics '$remote_addr - $remote_user [$time_local] ' + '"$request" $status $body_bytes_sent ' + '"$http_referer" "$http_user_agent" ' + '$request_time $upstream_response_time $bytes_sent'; diff --git a/source/stack/docker-serve/source/docker/nginx.conf b/source/stack/docker-serve/source/docker/nginx.conf index 801249e..8f100ba 100644 --- a/source/stack/docker-serve/source/docker/nginx.conf +++ b/source/stack/docker-serve/source/docker/nginx.conf @@ -14,6 +14,9 @@ server { # 运行时长不限制 fastcgi_read_timeout 60000; + # ulthon_admin nginx_log 分析:access_log 写到 runtime(持久化 + PHP 必能读) + access_log /var/www/html/runtime/nginx/access.log analytics; + location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; diff --git a/source/stack/docker-serve/source/docker/run.sh b/source/stack/docker-serve/source/docker/run.sh index c7630eb..fe2324c 100644 --- a/source/stack/docker-serve/source/docker/run.sh +++ b/source/stack/docker-serve/source/docker/run.sh @@ -20,6 +20,13 @@ mkdir -p /var/www/html/storage && chmod -R 777 /var/www/html/storage mkdir -p /var/www/html/memoryspace && chown -R www-data:www-data /var/www/html/memoryspace +# 复制 nginx_log 分析的 log_format 配置到 nginx http 块(conf.d 自动 include) +cp "$SCRIPT_DIR/nginx-log-format.conf" /etc/nginx/conf.d/ + +# 创建 nginx access_log 目录(必须在 service nginx start 之前) +mkdir -p /var/www/html/runtime/nginx && chmod 777 /var/www/html/runtime/nginx + + # 运行redis # nohup redis-server --requirepass "" & diff --git a/source/stack/full/source/docker/nginx-log-format.conf b/source/stack/full/source/docker/nginx-log-format.conf new file mode 100644 index 0000000..b7fc334 --- /dev/null +++ b/source/stack/full/source/docker/nginx-log-format.conf @@ -0,0 +1,6 @@ +# ulthon_admin nginx_log 分析专用 log_format +# 必须放在 nginx 的 http 块(通过 conf.d/*.conf 自动 include) +log_format analytics '$remote_addr - $remote_user [$time_local] ' + '"$request" $status $body_bytes_sent ' + '"$http_referer" "$http_user_agent" ' + '$request_time $upstream_response_time $bytes_sent'; diff --git a/source/stack/full/source/docker/nginx.conf b/source/stack/full/source/docker/nginx.conf index 801249e..8f100ba 100644 --- a/source/stack/full/source/docker/nginx.conf +++ b/source/stack/full/source/docker/nginx.conf @@ -14,6 +14,9 @@ server { # 运行时长不限制 fastcgi_read_timeout 60000; + # ulthon_admin nginx_log 分析:access_log 写到 runtime(持久化 + PHP 必能读) + access_log /var/www/html/runtime/nginx/access.log analytics; + location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; diff --git a/source/stack/full/source/docker/run.sh b/source/stack/full/source/docker/run.sh index c7630eb..fe2324c 100644 --- a/source/stack/full/source/docker/run.sh +++ b/source/stack/full/source/docker/run.sh @@ -20,6 +20,13 @@ mkdir -p /var/www/html/storage && chmod -R 777 /var/www/html/storage mkdir -p /var/www/html/memoryspace && chown -R www-data:www-data /var/www/html/memoryspace +# 复制 nginx_log 分析的 log_format 配置到 nginx http 块(conf.d 自动 include) +cp "$SCRIPT_DIR/nginx-log-format.conf" /etc/nginx/conf.d/ + +# 创建 nginx access_log 目录(必须在 service nginx start 之前) +mkdir -p /var/www/html/runtime/nginx && chmod 777 /var/www/html/runtime/nginx + + # 运行redis # nohup redis-server --requirepass "" &