Learn how to deploy Strapi on Ubuntu 24.04 using Nginx and PM2.
In today’s modern web development landscape, Strapi stands out as a powerful open-source headless CMS. Whether we’re building a personal blog, eCommerce backend, or enterprise-grade content hub, Strapi gives us full control of APIs, content types, and user roles. In this tutorial, we’ll walk through deploying a Strapi instance on an Ubuntu 24.04 server, using Nginx as a reverse proxy and PM2 for process management.
What is Strapi?
Strapi is an open-source headless CMS (Content Management System) built on Node.js. It allows developers to create and manage content through APIs without dealing with a traditional monolithic CMS. With Strapi, we can define custom content types, roles, permissions, and REST or GraphQL APIs — all from an easy-to-use admin panel.
Strapi is highly customizable, supports multiple databases (like PostgreSQL, MySQL, SQLite), and is perfect for building scalable, modern applications — whether it’s a blog, e-commerce backend, or mobile app API.
Prerequisites
Before we begin, let’s ensure our environment meets the following requirements:
- A Ubuntu 24.04 installed dedicated server or KVM VPS.
- A non-root user with sudo privileges.
- Basic knowledge of using the terminal.
- A domain name pointing to server IP.
Learn how to deploy Strapi on Ubuntu 24.04 using Nginx and PM2.
Step 1: Update the Server
We begin by updating the system packages. Keeping our server updated reduces vulnerabilities and ensures compatibility.
sudo apt update && sudo apt upgrade -y
Install essential tools:
sudo apt install curl wget git unzip -y
Step 2: Install Node.js and npm
Strapi requires Node.js (LTS version). Let’s install Node.js v22.x (recommended LTS).
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install nodejs -y
Verify:
node -v
npm -v
Step 3: Install Yarn (optional but recommended)
Yarn is often used for better dependency management in Node.js projects.
npm install -g yarn
Step 4: Install and Setup PostgreSQL (or use SQLite)
Strapi supports multiple databases. For production, PostgreSQL is the preferred choice.
sudo apt install postgresql postgresql-contrib -y
Create a database and user:
sudo -u postgres psql
Execute following commands:
CREATE DATABASE strapidb;
CREATE USER strapiuser WITH PASSWORD 'securepassword';
ALTER ROLE strapiuser SET client_encoding TO 'utf8';
ALTER ROLE strapiuser SET default_transaction_isolation TO 'read committed';
ALTER ROLE strapiuser SET timezone TO 'UTC';
GRANT ALL PRIVILEGES ON DATABASE strapidb TO strapiuser;
GRANT ALL ON SCHEMA public TO strapiuser;
ALTER SCHEMA public OWNER TO strapiuser;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO strapiuser;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO strapiuser;
\q
Replace 'securepassword' with a strong password.
Step 5: Create a Dedicated User for Strapi
To maintain separation of concerns, we use a non-root user:
sudo adduser strapi
sudo usermod -aG sudo strapi
su - strapi
Step 6: Install Strapi
Navigate to our working directory and create a Strapi project:
cd ~
npx create-strapi-app@latest my-strapi-app --dbclient=postgres --dbhost=127.0.0.1 --dbname=strapidb --dbport=5432 --dbusername=strapiuser --dbpassword=securepassword
Choose “custom (manual settings)” if prompted, and follow the interactive setup.
🚀 Welcome to Strapi! Ready to bring your project to life?
Create a free account and get:
✨ 30 days of access to the Growth plan, which includes:
✅ Single Sign-On (SSO) login
✅ Content History
✅ Releases
? Please log in or sign up. Skip
? Start with an example structure & data? Yes
? Start with Typescript? Yes
? Install dependencies with npm? Yes
? Initialize a git repository? Yes
Once installed, test it:
cd my-strapi-app
yarn develop
Step 7: Install PM2 to Run Strapi in Background
PM2 keeps our Strapi app alive and restarts it on failure or reboot.
sudo npm install -g pm2
Start Strapi with PM2:
cd ~/my-strapi-app
pm2 start yarn --name strapi -- start
To auto-start on reboot:
pm2 startup
pm2 save
Step 8: Configure Nginx as a Reverse Proxy
Install Nginx:
sudo apt install nginx -y
We need to add HTTP and HTTPS ports in firewall:
ufw allow 80/tcp
ufw allow 443/tcp
ufw reload
Create a new Nginx config file:
sudo nano /etc/nginx/sites-available/strapi
Paste the following:
server {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://127.0.0.1:1337;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Enable and restart Nginx:
sudo ln -s /etc/nginx/sites-available/strapi /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
Make sure DNS for yourdomain.com points to the server’s IP.
Step 9: Secure with SSL (Let’s Encrypt)
Let’s use Certbot to get a free SSL certificate.
sudo apt install certbot python3-certbot-nginx -y
Then run:
sudo certbot --nginx -d yourdomain.com
Follow prompts and select redirection to force HTTPS.
Step 10: Build Strapi
Go to your Strapi project directory:
cd /home/strapi/my-strapi-app
Build the admin panel:
yarn build
This command will compile the React-based admin panel and generate the necessary files under /build
.
Start Strapi with PM2 again:
pm2 restart strapi
Now it will find index.html and serve the admin panel properly.
Step 11: Access Strapi
Navigate your browser and access:
https://yourdomain.com
You will see one registration form to register the first admin user.
Step 12: Final PM2 Checks
Check status:
pm2 status
To view logs:
pm2 logs strapi
To restart:
pm2 restart strapi
Final Notes
- Strapi’s admin panel should now be live at https://yourdomain.com/admin.
- Don’t forget to configure proper CORS and security settings in ./config/middlewares.js.
- Always disable yarn develop and use yarn start in production.
- Use firewall rules and keep regular backups.
By following these steps, we’ve deployed a secure and production-ready Strapi CMS on Ubuntu 24.04. With Nginx handling traffic and PM2 managing uptime, we’ve built a solid foundation for scaling content applications.
Checkout our low cost dedicated servers.