使用basePath的Next.js不使用nginx部署渲染图像

3phpmpom  于 2024-01-06  发布在  Nginx
关注(0)|答案(2)|浏览(200)

我已经在Ubuntu 16.0.4上使用nginx部署了我的Next.js应用程序。
我已经在根mywebsite.com上部署了一个运行良好的应用程序。我正在尝试在mywebsite.com/some-keyword上使用basePath部署此应用程序。
该应用程序似乎工作正常,但不渲染图像。
我该如何解决此问题?
Nginx更新:

  1. location /some-keyword {
  2. proxy_pass http://localhost:8000;
  3. proxy_http_version 1.1;
  4. proxy_set_header Upgrade $http_upgrade;
  5. proxy_set_header Connection 'upgrade';
  6. proxy_set_header Host $host;
  7. proxy_cache_bypass $http_upgrade;
  8. # First attempt to serve request as file, then
  9. # as directory, then fall back to displaying a 404.
  10. # try_files $uri $uri/ =404;
  11. }

字符串
next.config.js

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


使用next/image如下:

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

bogh5gae

bogh5gae1#

从Next.js Base Path文档:
使用next/image组件时,需要在src之前添加basePath
在您的例子中,假设您的basePath/some-keyword,您的代码应该如下所示:

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

字符串

klsxnrf1

klsxnrf12#

next.config.js中添加以下内容:

  1. images: {
  2. domains: ['yourdomain.com'],
  3. unoptimized: true,
  4. },

字符串
这帮助我解决了我在运行NGINX服务器的Ubuntu 20.04上的一些图像加载问题。

相关问题