next.js ERR_TLS_CERT_ALTNAME_INVALID(使用带有外部URL的下一个映像时)

mec1mxoz  于 2023-11-18  发布在  其他
关注(0)|答案(1)|浏览(119)

我有一个自定义域,其子域指向AWS S3存储桶(如images.domain.com)。我可以让用户上传图像并在存储桶中查看它。我可以使用生成的URL访问图像,该URL也在数据库中的用户数据中。
当我尝试在Next Image中使用此URL作为src时,我得到以下错误:

TypeError: fetch failed
    at Object.fetch (node:internal/deps/undici/undici:11576:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  cause: Error [ERR_TLS_CERT_ALTNAME_INVALID]: Hostname/IP does not match certificate's altnames: Host: images.domain.com. is not in the cert's altnames: DNS:s3-us-west-1.amazonaws.com, DNS:*.s3-us-west-1.amazonaws.com, DNS:s3.us-west-1.amazonaws.com, DNS:*.s3.us-west-1.amazonaws.com, DNS:s3.dualstack.us-west-1.amazonaws.com, DNS:*.s3.dualstack.us-west-1.amazonaws.com, DNS:*.s3.amazonaws.com, DNS:*.s3-control.us-west-1.amazonaws.com, DNS:s3-control.us-west-1.amazonaws.com, DNS:*.s3-control.dualstack.us-west-1.amazonaws.com, DNS:s3-control.dualstack.us-west-1.amazonaws.com, DNS:*.s3-accesspoint.us-west-1.amazonaws.com, DNS:*.s3-accesspoint.dualstack.us-west-1.amazonaws.com, DNS:*.s3-deprecated.us-west-1.amazonaws.com, DNS:s3-deprecated.us-west-1.amazonaws.com

字符串
我将我的自定义子域添加到next.config.js

images: {
    formats: ['image/avif', 'image/webp'],
    remotePatterns: [
      {
        protocol: 'https',
        hostname: 'images.domain.com',
      },
    ],
  },


我可以使用标准的<img>标签加载图像,但我想利用NextJS中的Image组件。我使用NextJS 13.5.4在本地运行它。

lpwwtiir

lpwwtiir1#

S3网站不支持https,来自docs
Amazon S3网站端点不支持HTTPS。如果要使用HTTPS,可以使用Amazon CloudFront为Amazon S3上托管的静态网站提供服务。
如文档中所述,您必须设置Amazon CloudFront以使用HTTPS。

相关问题