To set up a Strapi CMS under a subfolder (e.g., https://example.com/blog/) using Nginx, there are multiple steps required.
By default, Strapi is served at the root / of the domain (i.e., http://localhost:1337/). If you want it under a subfolder like /blog/, both Strapi and your Nginx reverse proxy need to be configured accordingly.
✅ Goal
Run Strapi at:
code
https://example.com/blog/
✅ Prerequisites
Installed Node.js & NPM/Yarn.
Strapi project (e.g., /var/www/strapi-app).
Strapi available on localhost:1337.
Nginx installed and serving another app/domain correctly.
🔧 Step-by-Step Configuration
1. Configure Strapi to Use a Subfolder
Strapi must be aware it's behind a proxy and served from a subfolder (/blog/).
Sends proper headers for Websockets and other functionality.
Serves uploaded assets if needed.
4. Restart and Build
After changes are done:
bash
# Navigate to your strapi project
cd /var/www/strapi-app
# Rebuild admin panel with correct base path
npm run build
# Start Strapi
npm run develop # or use PM2 / forever for production
For production, prefer:
bash
NODE_ENV=production npm run build
NODE_ENV=production npm start
✅ Optional: Serve Admin Panel Behind Subfolder Only
If you need to serve only the Admin panel (and not the API) behind /blog/, you’d need more advanced Nginx rewriting and potentially multiple Strapi instances or frontend routing. But the current setup exposes both admin and API under /blog/, which is the usual desired behavior.