nextjs
config_error
ai_generated
true
错误:URL '...' 的图像优化失败,因为协议不被允许。仅支持 'https:'。
Error: Image optimization for URL '...' failed because the protocol is not allowed. Only 'https:' is supported.
ID: nextjs/invalid-image-optimization-url-protocol
88%修复率
90%置信度
1证据数
2024-01-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| [email protected] | active | — | — | — |
| [email protected] | active | — | — | — |
| [email protected] | active | — | — | — |
根因分析
next/image 组件或 Image API 尝试使用 http:// URL 优化图像,但出于安全原因,Next.js 默认只允许 https:// URL。
English
The next/image component or Image API is trying to optimize an image with an http:// URL, but Next.js only allows https:// URLs by default for security reasons.
官方文档
https://nextjs.org/docs/messages/invalid-image-optimization-url-protocol解决方案
-
在 next.config.js 中添加 dangerousAllowingHttp 选项以允许 http:// URL。请谨慎使用。
-
如果您控制图像源,请使用 CDN 或 SSL 证书迁移到 https://。
-
在 next.config.js 中使用代理或重写,通过 https 端点提供 http 图像。
无效尝试
常见但无效的做法:
-
80% 失败
If the image server does not support https, the image will not load.
-
70% 失败
This removes all optimization benefits and may increase page load times.
-
85% 失败
The protocol check is separate from the hostname check; you need to explicitly allow http.