Question

Next.JS Deployment to Nginx Droplet

I’m currently attempting to deploy my Next.js SSG application to the same droplet that my backend graphql api is hosted on. The api sits at /graphql while the app sits at /app but when I navigate to /app I get a loading… page with console showing the server is "404"ing the page.

I’m not getting any errors on the Next.js side of npm run build and npm start or with pm2 in actually starting the website. It’s clearly pulling from the next.js app as some of the resources its failing to grab are _app.js which is the root file for my next.js app.

I thought it might be an environmental variable thing but I have the same next.config.js file as my local version on the server and my local version works in both dev and production mode.

Any help on this would be greatly appreciated.


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.

Accepted Answer

Solved the problem it turns out that I hadn’t properly set up the express server to operate on the correct root it was / and it should’ve been replaced with /api

Hi there @milorue,

Can you share the exact Nginx Server block that you are using for your setup? I could then try to advise you further.

Also what I could suggest is checking your Nginx error log for any errors that could provide you with more information:

  1. tail -100 /var/log/nginx/error.log

Regards, Bobby

Try DigitalOcean for free

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

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.