Nextjs + nginx + serve images

Hi i followed to the tutorials how to set up ubuntu, nginx, pm2. i set up nginx + nextjs 13. text content is served well.

i have an issue with serving images together with nextjs optimization mechanizm.

for some reason request www.uppr[.]com[.]ua/_next/image?url=%2Fassets%2Fimages%2Fblog-articles%2Facronyms_which_you_should_use_in_emails_main.jpg&w=1920&q=75 gives me 500 error.

I read information in internet and understood that it is due to double routing on nginx side and nextjs server side.

Please could you provide example of the correct configuration for the nginx + nextjs for such cases.

site for example is uppr[.]com[.]ua/blog

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

hey @dmytro, did you find a solution to your problem? I’m having the same issue too and cannot solve it for days already.

Bobby Iliev
Site Moderator
Site Moderator badge
January 23, 2023

Hi there,

I could suggest starting with the following:

  • Check your Nginx error log to see if there are any errors in there that could indicate a problem with the configuration:
tail -100 /var/log/nginx/error.log
  • Check your Node.js logs using to see if the problem is related with the app itself:
pm2 logs

That way you should be able to see the actual error causing the problem rather than the generic 500 error.

Feel free to share the error here so we could try to advise you further!



Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel