Image Optimization returns 403 on Vercel #85154
-
Summarynext/image works locally, but on Vercel I get 403 or broken images. What is the correct images.domains or remotePatterns config to allow external images? Additional informationNo response ExampleNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
The image’s origin domain isn’t allow-listed (or the origin blocks hotlinking). Add the host to images.domains (simple) or use images.remotePatterns (granular). If the origin blocks Vercel’s optimizer, proxy the image through your app. ✅ Allow-list the image host next.config.js (simple host allow-list) // next.config.js next.config.js (granular patterns) // next.config.js After changing next.config.js, redeploy. 🧪 If it’s still 403 Hotlink protection / required headers: Some CDNs require a Referer or block non-browser fetches. Protocol/host mismatch: The runtime URL must exactly match what you allow-listed (https vs http, www. vs bare, correct subdomain). Static export: If using next export, image optimization isn’t supported: // next.config.js SVGs: next/image doesn’t transform remote SVGs; serve them directly (or ✅ Minimal working example export default function Hero() { |
Beta Was this translation helpful? Give feedback.
The image’s origin domain isn’t allow-listed (or the origin blocks hotlinking). Add the host to images.domains (simple) or use images.remotePatterns (granular). If the origin blocks Vercel’s optimizer, proxy the image through your app.
✅ Allow-list the image host
next.config.js (simple host allow-list)
// next.config.js
module.exports = {
images: {
domains: [
"images.unsplash.com",
"cdn.example.com",
"lh3.googleusercontent.com",
],
},
};
next.config.js (granular patterns)
// next.config.js
module.exports = {
images: {
remotePatterns: [
{
protocol: "https",
hostname: "images.unsplash.com",
pathname: "/photo-",
},
{
protocol: "https",
hostname: "cdn.example.com",
pathname: "/products/",
},
{
…