1

I have deployed my Next.js app on Ubuntu 16.0.4 with nginx.

I already have an app deployed on the root mywebsite.com which is working fine. I'm trying deploy this app with a basePath at mywebsite.com/some-keyword.

The app seems to work fine but not rendering the images.

How can I fix this?

Nginx updates:

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'
};

Using next/image like so:

<Image src='/img/alert-down.png' width={550} height={320} />
4
  • What do you see in the Network tab in dev tools for the images requests? Are they 404ing? Commented Jun 13, 2021 at 9:58
  • I have also tried https://mywebsite.com/_next/image?url=params but it also didn't work Commented Jun 13, 2021 at 22:03
  • Are you using next/image component by any chance? Can you share some code of how you're setting an image? Commented Jun 13, 2021 at 22:05
  • Yeah using next/image like so <Image src='/img/alert-down.png' width={550} height={320} /> Commented Jun 13, 2021 at 22:07

2 Answers 2

1

From the Next.js Base Path docs:

When using the next/image component, you will need to add the basePath in front of src.

In your case, assuming your basePath is /some-keyword your code should look like:

<Image src='/some-keyword/img/alert-down.png' width={550} height={320} />
Sign up to request clarification or add additional context in comments.

Comments

0

In your next.config.js add the following:

images: {
    domains: ['yourdomain.com'],
    unoptimized: true,
},

This helped me resole some of my image loading problems on Ubuntu 20.04 running NGINX server.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.