Magento Cloud is a powerful eCommerce platform that allows businesses to scale and manage their online stores effectively. One of the critical features it offers is the ability to put a store into maintenance mode while keeping others functional. This can be incredibly useful when you need to perform updates, fixes, or troubleshooting tasks on a specific store without affecting the entire platform.
In this blog post, we’ll walk you through the steps to put a single store in maintenance mode using Custom VCL Snippets in Magento Cloud. We’ll use Magento’s Full Page Cache (FPC) system and create two custom VCL snippets: one for intercepting the incoming request and another for redirecting the user to a maintenance page.
What Is a VCL Snippet?
VCL (Varnish Configuration Language) snippets are used to configure Varnish, the caching engine that Magento Cloud uses to accelerate web performance. By using VCL snippets, you can create custom behaviors, including serving maintenance pages based on specific conditions.
Now, let’s dive into the steps to set up maintenance mode for a single store.
Steps to Enable Maintenance Mode for a Single Store
To configure this, you will need access to your Magento Cloud Admin Panel, specifically the Custom VCL Snippet section under Full Page Cache settings.
1.
Navigate to the Custom VCL Snippet Configuration
- Log in to Magento Cloud Admin.
- Go to Stores > Settings > Configuration.
- Under Advanced > System, click Full Page Cache.
- Scroll down to Custom VCL Snippets
2.
Create a Custom VCL Snippet for Maintenance Mode
The first VCL snippet is designed to intercept incoming requests and check if they belong to the store you wish to put into maintenance mode. If so, it redirects those requests to a custom 503 error page.
- Click Add New Custom VCL Snippet.
- Fill in the following details:
- Name: AU_webstore_maintenance
- Type: recv
- Priority: 10
- Under the VCL code section, add the following:
# Check if the request comes from your specific store domain
if (req.http.host == "your.site.com") {
# Ensure we are not already serving the 503 maintenance page
if (req.url !~ "^/errors/503.php") {
error 752 "Maintenance";
}
}
- The VCL checks if the incoming request belongs to the specific store (for instance, “your.site.com”).
- If the requested URL is not the maintenance page itself (503.php), it triggers an error with the status code 752 to handle the request as a maintenance request.
3.
Create Another VCL Snippet for Error Handling
After intercepting the request, you need another VCL snippet that will redirect users to the 503 maintenance page. This is accomplished by setting up a VCL error snippet.
- Again, click Add New Custom VCL Snippet.
- Fill in the following details:
- Name: AU_webstore_maintenance
- Type: error
- Priority: 10
- Under the VCL code section, add the following:
if (obj.status == 752) {
set obj.status = 302;
set obj.response = "Found";
set obj.http.Location = "https://your.site.com/errors/503.php";
return (deliver);
}
- If the error status code 752 is detected (set by the first snippet), the VCL will issue a 302 redirect to the custom maintenance page located at /errors/503.php.
- The user is then redirected to the maintenance page, informing them that the store is temporarily down for maintenance.
4.
Apply and Test Your Changes
After setting up both VCL snippets, make sure to test your changes:
- Clear the Magento Cache.
- Try accessing your store using the store’s specific URL (e.g., your.site.com).
- Ensure that the store is correctly redirecting to the 503.php page.
- If everything works, your store is now in maintenance mode, while other stores remain unaffected.
Conclusion
By following these steps, you can easily put a single store into maintenance mode in Magento Cloud without affecting your other stores. Using Custom VCL Snippets gives you granular control over the behavior of each store, ensuring minimal disruption to your overall eCommerce operations.
If you need to bring the store back online, you can simply disable or remove the VCL snippets, and the store will be live again.
For businesses operating multiple stores on Magento Cloud, this method ensures that critical updates or fixes can be made to one store while keeping others running smoothly.
Would you like more tips or insights on managing your Magento store? Let us know in the comments!
Leave A Comment