Next JS 不渲染图像 ubuntu 和 nginx 部署

时间:2021-06-11 20:44:18

标签: nginx next.js nextjs-image

我已经使用 nginx 在 Ubuntu 16.0.4 上部署了我的 Next.js 应用程序。

我已经在根 mywebsite.com 上部署了一个运行良好的应用程序。我正在尝试在 mywebsite.com/some-keyword

部署此应用程序

该应用似乎运行良好,但无法渲染图像。

我该如何解决这个问题?

Nginx 更新:

location /some-keyword {
  proxy_pass http://localhost:8000;
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection 'upgrade';
  proxy_set_header Host $host;
  proxy_cache_bypass $http_upgrade;

  # First attempt to serve request as file, then
  # as directory, then fall back to displaying a 404.
  # try_files $uri $uri/ =404;
}

next.config.js

module.exports = {
  basePath: '/some-keyword'
};

1 个答案:

答案 0 :(得分:1)

来自 Next.js Base Path docs

<块引用>

使用 next/image 组件时,您需要在 basePath 前添加 src

就您而言,假设您的 basePath/some-keyword,您的代码应该如下所示:

<Image src='/some-keyword/img/alert-down.png' width={550} height={320} />