# Windows Web 服务器的日志、审计与 SIEM

> 收集 IIS/Nginx 访问日志、Windows 安全事件和应用日志，校准时间/保留，并只对有意义的事件告警。

**测试环境**

- 版本号: 26100.33650
- 版本: Standard / Datacenter
- 架构: x64
- 证据: E1
- 核验日期: 2026-10-29

## 一句话结论

收集四路：

1. **Web 访问** — IIS W3C / Nginx access。
2. **Web 错误** — IIS failed request tracing / Nginx error。
3. **Windows** — Security、System、Application。
4. **应用** — stdout/stderr、结构化 JSON。

外送；本机日志随主机一起消失。

## 保留什么

- 带时区的时间、服务器、站点/host、客户端 IP、方法、路径、状态、字节、延迟；
- 认证用户（安全前提下）、UA；
- request id/关联 id。

不要记录密码、token、完整 cookie、卡数据或敏感查询串。在应用/代理脱敏。

## IIS

默认 `C:\inetpub\logs\LogFiles\W3SVC<id>\`。设保留、移出系统盘，500 开失败请求跟踪。IIS 是 W3C 文本，字段要显式解析。

## Nginx

```nginx
log_format main '$remote_addr - $host [$time_local] "$request" '
                '$status $body_bytes_sent "$http_referer" "$http_user_agent" '
                'rt=$request_time uct=$upstream_connect_time urt=$upstream_response_time';
access_log C:/nginx/logs/access.log main;
error_log  C:/nginx/logs/error.log warn;
```

真实客户端 IP 只信代理；否则 XFF 可伪造。

## Windows 审计

至少开：

- 登录成功/失败；
- 账户管理；
- 进程创建（能承受量才开）；
- 服务安装/变更；
- PowerShell script block（合适时）。

用 Windows Event Forwarding 或 agent 转发。域控/PAW 路径与 Web 层分开。

## SIEM/告警

有用告警：

- 单 IP 的 401/403/404 激增；
- 部署后 500 激增；
- Web 服务器出现新服务/进程；
- IIS 应用池崩溃循环；
- 证书 14 天内到期；
- 日志/临时盘满；
- Web 层向异常主机外连。

> **警告: 日志是证据，不是备份**
>
> 日志帮调查，但不能恢复服务器。配置/内容/证书单独备份；日志防篡改（尽量集中只写存储）。

## 验证

```powershell
Get-WinEvent -LogName Security -MaxEvents 5
Get-Content C:\inetpub\logs\LogFiles\W3SVC2\*.log -Tail 5
```

确认 SIEM 里出现同一事件，时区和字段正确。

## 实验室边界

E1。实验室有 IIS 日志和 Windows 事件，但没有集中 SIEM/转发器。流和告警是 Server 2025 的生产设计。

## 来源

- [Microsoft Learn — IIS 日志](https://learn.microsoft.com/zh-cn/iis/manage/provisioning-and-managing-iis/configure-logging-in-iis)
- [nginx — 日志](https://nginx.org/en/docs/http/ngx_http_log_module.html)

---

来源页面: https://winbook.fyi/zh/server/security/logging/
