Part 91: Deploying a Next.js App with a Remote Strapi CMS: A Practical Guide
[App] Deploying with External Services

Integrating a Next.js application with a CMS like Strapi is an excellent way to manage content effectively, especially as your application scales. While running Strapi locally is straightforward, deploying it for production use involves several steps. In this post, we'll explore how to set up a production-ready Strapi server and configure your Next.js app to connect to it.
Why Use a Remote CMS for Production?
Using a remote CMS, such as Strapi, in production allows your application to access content from a centralized source. This is beneficial for collaboration, as other team members can easily access and manage content. It also enables your app to serve content consistently across different environments.
Setting Up a Production Strapi Server
Option 1: Self-Hosted Strapi
Strapi is open-source, giving you the flexibility to host it on your own server. This approach requires some technical expertise:
Choose a Hosting Provider: You can use services like Amazon Web Services (AWS), Microsoft Azure, or DigitalOcean. Each of these platforms has its own setup process.
Database Configuration: In production, you'll likely use databases like MySQL or Postgres. Strapi supports various databases, but you'll need to set up and configure one that suits your needs.
File Storage: For image storage, consider using a cloud storage service such as Amazon S3, which is more reliable than local storage.
Running Strapi: Deploy the Strapi application on a server, usually a Linux-based system, using Node.js. This might involve setting up an EC2 instance if you're using AWS.
Option 2: Strapi Cloud
If setting up and maintaining your own server sounds daunting, Strapi Cloud offers a fully managed hosting solution:
Easy Setup: Strapi Cloud handles the deployment, scaling, and management of your Strapi instance, similar to other managed platforms.
Trial Period: Note that Strapi Cloud offers a 14-day trial, but requires a subscription afterward.
Integrating Next.js with a Remote Strapi Instance
Once your Strapi server is set up, you'll need to update your Next.js configuration to connect to it.
Step 1: Configure Environment Variables
To switch from a local to a remote Strapi instance, update your .env.local file with the new CMS URL:
# Local configuration (commented out)
# CMS_URL=http://localhost:1337
# CMS_IMAGE_PATTERN="http://localhost:1337/uploads/**"
# Remote configuration
CMS_URL=https://your-remote-strapi-url.com
CMS_IMAGE_PATTERN="https://your-remote-strapi-url.com/uploads/**"Step 2: Update Image Optimization Configuration
In next.config.js, ensure the image patterns align with your remote setup:
module.exports = {
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'your-remote-strapi-url.com',
pathname: '/uploads/**',
},
],
},
};Step 3: Handle Remote Image URLs
When deploying, you might encounter issues with image URLs. For example, Strapi Cloud might store images on a separate domain like media.strapiapp.com. Ensure your configuration accounts for this:
module.exports = {
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'media.strapiapp.com',
pathname: '/uploads/**',
},
],
},
};Step 4: Testing Locally
Before deploying the Next.js app, test it locally with the remote Strapi configuration. This helps identify and resolve any issues with API requests or image loading.
Conclusion
Deploying a Next.js app with a remote CMS like Strapi involves several steps, but it significantly enhances the scalability and collaboration capabilities of your application. Whether you choose to self-host or use a managed service like Strapi Cloud, configuring environment variables and updating your Next.js settings are key steps in the process.
As you explore different CMS options, remember to consider your specific project requirements and choose the solution that best fits your needs. For more detailed instructions on deploying Strapi, refer to the Strapi Deployment Documentation.
Last updated