You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Next.js中next/image加载公网IP图片报错问题求助

Next.js next/image加载公网IP图片报错的解决方法

你遇到的问题核心是next.config.js中remotePatterns的配置错误:hostname字段不能包含端口号,端口需要单独通过port属性指定。

修正后的next.config.js配置

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
  optimizeFonts: true,
  images: {
    remotePatterns: [
      {
        protocol: 'http',
        hostname: '110.100.190.222', // 仅保留IP,移除端口
        port: '9790', // 单独指定端口
        pathname: '/images/**', // 可选,限制匹配路径,提升安全性
      },
    ],
    minimumCacheTTL: 1500000,
  },
}

module.exports = nextConfig

额外注意事项

  • 修改next.config.js后,必须重启Next.js开发服务器,配置才会生效。
  • 确认公网IP对应的图片服务允许跨域访问,或者Next.js服务器能正常请求到该IP资源(比如防火墙、安全组是否开放9790端口)。
  • 确保item.article_image_path拼接后的路径正确,避免出现重复斜杠(比如若article_image_path以/开头,需避免生成/images//xxx这类异常路径)。

内容的提问来源于stack exchange,提问作者Mr-T

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 08:35:21