By raymond53892
I’ve currently got a Flask server running via Nginx + Gunicorn on a droplet, and a client website hosted on another hosting provider which connects to the Flask server via a subdomain (api.mydomain.com). Is it possible to serve the NextJS website from the same droplet at the root domain (mydomain.com)? If so, how can this be achieved using Nginx?
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!
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.
Hi,
That’s doable. You’d create a new server block in Nginx for mydomain.com just like you have created for api.mydomain.com and configure the NextJS location block as described on their site:
https://github.com/zeit/next.js/wiki/Deployment-on-Nginx’s-reverse-proxy
Cheers
Hey, thanks for replying!
I’ve followed the instructions on that link, and now I think there’s an issue with the NextJS server not running correctly. I start the server using pm2 start npm --name "next" -- start
But I’m getting this error in the nginx logs.
connect() failed (111: Connection refused) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: mydomain.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:3000/", host: "mydomain.com"
Is there anything else I need to do to get it to work?
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.
