# 错误：URL '...' 的图像优化失败，因为协议不被允许。仅支持 'https:'。

- **ID:** `nextjs/invalid-image-optimization-url-protocol`
- **领域:** nextjs
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 88%

## 根因

next/image 组件或 Image API 尝试使用 http:// URL 优化图像，但出于安全原因，Next.js 默认只允许 https:// URL。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| next@13.5.0 | active | — | — |
| next@14.0.0 | active | — | — |
| next@14.2.12 | active | — | — |

## 解决方案

1. ```
   在 next.config.js 中添加 dangerousAllowingHttp 选项以允许 http:// URL。请谨慎使用。
   ```
2. ```
   如果您控制图像源，请使用 CDN 或 SSL 证书迁移到 https://。
   ```
3. ```
   在 next.config.js 中使用代理或重写，通过 https 端点提供 http 图像。
   ```

## 无效尝试

- **** — If the image server does not support https, the image will not load. (80% 失败率)
- **** — This removes all optimization benefits and may increase page load times. (70% 失败率)
- **** — The protocol check is separate from the hostname check; you need to explicitly allow http. (85% 失败率)
