This content originally appeared on DEV Community and was authored by Bobby Orphé HOUESSINON
Introduction
Deploying a full-stack application that consists of a NestJS backend and a Next.js frontend on a Dokku server can be a powerful yet cost-effective solution. This article will guide you through the process of orchestrating both applications on a single Dokku instance.
Prerequisites
Before proceeding, ensure you have the following:
A server with Dokku installed (installation guide in this article)
A domain name (optional but recommended)
Basic knowledge of NestJS, Next.js, and Docker
Step 1: Setting Up the Dokku Applications
On your server, create two Dokku applications:
Create applications
dokku apps:create my-nestjs-app
dokku apps:create my-nextjs-app
Set up database and environment variables
# Example for database
dokku plugin:install https://github.com/dokku/dokku-postgres.git
dokku postgres:create mydatabase
dokku postgres:link mydatabase my-nestjs-app
# Example for environment variables
dokku config:set my-nestjs-app \
APP_PORT=5000 \
NGINX_ROOT=dist \
JWT_SECRET=xxxxxxxxxxxxxxxxxx
Step 2: Configuring NestJS for Deployment
Ensure your NestJS project has a Procfile
on the root folder:
web: npm run prod
Then, deploy your NestJS backend:
git remote add dokku dokku@your-server-ip:my-nestjs-app
git push dokku main
Step 3: Configuring Next.js for Deployment
Next.js can be deployed similarly, but with custom environment variables:
dokku config:set my-nextjs-app \
NEXT_PUBLIC_API_URL="https://api.yourdomain.com" \
NGINX_ROOT=.next
Ensure your Next.js project has a Procfile
:
web: npm run prod
Deploy with:
git remote add dokku dokku@your-server-ip:my-nextjs-app
git push dokku main
Step 4: Configuring Nginx and Domains
If using domains, set them up with:
dokku domains:set my-nestjs-app api.yourdomain.com
dokku domains:set my-nextjs-app yourdomain.com
Enable SSL with Let's Encrypt:
dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git
dokku letsencrypt my-nestjs-app
dokku letsencrypt my-nextjs-app
Step 5: Testing the Deployment
Verify both applications are running:
dokku logs my-nestjs-app
dokku logs my-nextjs-app
Visit https://yourdomain.com for the frontend and https://api.yourdomain.com for the backend.
Conclusion
By following this guide, you've successfully deployed a full-stack NestJS + Next.js application on a Dokku server. This setup allows for scalability, easy updates, and a structured separation between the frontend and backend.
Further Reading
Let me know in the comments if you have any questions or need clarifications!
This content originally appeared on DEV Community and was authored by Bobby Orphé HOUESSINON

Bobby Orphé HOUESSINON | Sciencx (2025-02-22T12:34:59+00:00) Deploying a NestJS and Next.js Application on Dokku: Full-Stack Architecture. Retrieved from https://www.scien.cx/2025/02/22/deploying-a-nestjs-and-next-js-application-on-dokku-full-stack-architecture/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.