帮助文档

Nginx概述

Nginx是一款高性能的Web服务器、反向代理和负载均衡器,适用于现代Web架构。其以高效、稳定和低资源消耗著称,非常适合处理高流量网站。

Nginx扩展范围

Log360 Cloud的Nginx扩展支持将Nginx日志集成到Log360 Cloud生态系统中。该扩展提供日志收集、解析、报告、告警、关联和高级日志搜索等功能,用于监控Web流量和服务器性能。

配置Nginx日志格式

配置Nginx并定义自定义访问日志格式,请按照以下步骤操作:

1. 打开Nginx配置文件

在系统中找到Nginx配置文件:

  • Windows: 进入NginxDirectory/nginx.conf,使用文本编辑器打开。
  • Linux: 运行以下命令打开文件:sudo nano /etc/nginx/nginx.conf

2. 定义自定义访问日志格式

在nginx.conf文件的http块内,添加以下日志格式定义:

复制到剪贴板

log_format event_log_analyzer 'time_local="$time_local" connection="$connection" realip_remote_addr="$realip_remote_addr" remote_addr="$remote_addr" host="$host" remote_port="$remote_port" remote_user="$remote_user" server_name="$server_name" server_addr="$server_addr" server_port="$server_port" request="$request" uri="$uri" http_referer="$http_referer" http_user_agent="$http_user_agent" request_filename="$request_filename" http_cookie="$http_cookie" sent_http_content_type="$sent_http_content_type" http_x_forwarded_for="$http_x_forwarded_for" proxy_host="$proxy_host" status="$status" bytes_sent="$bytes_sent" https="$https" request_time="$request_time" ssl_cipher="$ssl_cipher" ssl_protocol="$ssl_protocol" upstream_addr="$upstream_addr" upstream_status="$upstream_status" upstream_bytes_received="$upstream_bytes_received" upstream_response_time="$upstream_response_time" upstream_cache_status="$upstream_cache_status"';

3. 指定访问日志位置

在http块内,定义访问日志的存储位置并应用自定义日志格式。请参考以下示例:

Format: access_log location log_format_name;
Example: access_log /var/log/nginx/access.log log360_nginx;

4. 重新加载Nginx以应用更改

配置更改完成后,重新加载Nginx以使更改生效。

  • Windows: 在命令提示符中运行以下命令:

    nginx -s reload

  • Linux: 运行以下命令:

    sudo systemctl reload nginx

在Log360 Cloud中配置

在Log360 Cloud中安装Nginx扩展后,配置从Nginx服务器文件路径定期导入 access.log 文件。确保在配置时使用正确的文件路径。

导航至 设置 → 配置设置 → 日志源配置 → 导入日志 → 设备导入

注意:请参阅 导入日志 文档中的分步操作。默认的Nginx日志格式不会被自动识别。导入默认日志时,除上述自定义格式外,您需要手动选择日志格式。

审计的Nginx事件

以下是Log360 Cloud中从Nginx捕获的审计事件类型:

类别 事件
Nginx Web服务器事件 Web服务器流量、请求率、每会话请求数、访问的URI、虚拟服务器事件、访问的文件、SSL成功事件、SSL握手失败
Web服务器HTTP状态码 成功事件、重定向事件、客户端错误、服务器端错误
Nginx上游事件 上游请求、上游重定向、缓存效率

查看Nginx报告

要查看Nginx报告,请导航至 报告 选项卡并选择 Nginx 子选项卡中的 自定义报告

Nginx

启用Nginx告警

要查看告警,导航至 警报 选项卡 -> 管理告警配置文件。

  1. 管理告警配置文件 页面,选择 自定义告警配置文件 作为 告警配置文件类型。点击搜索图标,添加Nginx以筛选告警配置文件。选择配置文件,点击绿色勾选图标 icon-enable 启用告警配置文件。
  2. Nginx

  3. 要关联日志源,点击编辑图标打开 编辑告警配置文件 窗口。在 日志源 字段,点击添加按钮,选择已配置的Nginx日志源。 点击 更新 保存更改。 © 2025 Zoho Corporation Pvt. Ltd. 版权所有。
  4. Nginx