nextjs
config_error
ai_generated
true
Error: Image optimization for URL '...' failed because the protocol is not allowed. Only 'https:' is supported.
ID: nextjs/invalid-image-optimization-url-protocol
88%Fix Rate
90%Confidence
1Evidence
2024-01-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| [email protected] | active | — | — | — |
| [email protected] | active | — | — | — |
| [email protected] | active | — | — | — |
Root Cause
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.
generic中文
next/image 组件或 Image API 尝试使用 http:// URL 优化图像,但出于安全原因,Next.js 默认只允许 https:// URL。
Official Documentation
https://nextjs.org/docs/messages/invalid-image-optimization-url-protocolWorkarounds
-
90% success Add the dangerousAllowingHttp option to next.config.js to allow http:// URLs. Use with caution.
Add the dangerousAllowingHttp option to next.config.js to allow http:// URLs. Use with caution.
-
95% success If you control the image source, migrate to https:// using a CDN or SSL certificate.
If you control the image source, migrate to https:// using a CDN or SSL certificate.
-
80% success Use a proxy or rewrite in next.config.js to serve http images through an https endpoint.
Use a proxy or rewrite in next.config.js to serve http images through an https endpoint.
中文步骤
在 next.config.js 中添加 dangerousAllowingHttp 选项以允许 http:// URL。请谨慎使用。
如果您控制图像源,请使用 CDN 或 SSL 证书迁移到 https://。
在 next.config.js 中使用代理或重写,通过 https 端点提供 http 图像。
Dead Ends
Common approaches that don't work:
-
80% fail
If the image server does not support https, the image will not load.
-
70% fail
This removes all optimization benefits and may increase page load times.
-
85% fail
The protocol check is separate from the hostname check; you need to explicitly allow http.