Serving NextJS along with Python api on Nginx

January 2, 2019 2k views
Nginx Python Node.js Initial Server Setup Ubuntu 18.04

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 ( Is it possible to serve the NextJS website from the same droplet at the root domain ( If so, how can this be achieved using Nginx?

2 Answers


That’s doable. You’d create a new server block in Nginx for just like you have created for and configure the NextJS location block as described on their site:’s-reverse-proxy


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:, server:, request: "GET / HTTP/1.1", upstream: "", host: ""

Is there anything else I need to do to get it to work?

Have another answer? Share your knowledge.