Skip to content

Instantly share code, notes, and snippets.

@vasilii-b
Created October 29, 2024 06:53
Show Gist options
  • Save vasilii-b/3d085f93f5f32dfa23100fbe2dde82e2 to your computer and use it in GitHub Desktop.
Save vasilii-b/3d085f93f5f32dfa23100fbe2dde82e2 to your computer and use it in GitHub Desktop.
Adobe Commerce / Magento 2 Maintenance page with Fastly for specific website

The bellow Fastly recv ACL rule will allow to redirect the users to a custom maintenance page (even a CMS page if you like) for a specific domain.

It will still allow the /media and static content (themes) files to be viewed - which allows to build custom maintenance pages right in the admin area with CMS Pages.

Also, it's taking into account the list of IPs to whitelist from the redirect using the Fastly Edge ACL - in this example the name is maint_allowlist.

This comes in hand when you've got an Adobe Commerce/ Magento 2 instance powering multiple websites. That's because with the built-in maintenance page (whic is enabled via CLI bin/magento maintenance:enable) this will affect all websites, not only the one you'd like.

if (
  req.http.host ~ "your-domain\.com" &&
  (
    req.url !~ "^/maintenance-page-url" &&
    req.url !~ "^/static" &&
    req.url !~ "^/media"
  ) &&
  !(client.ip ~ maint_allowlist) &&
  !req.http.Fastly-FF
) {
   set req.url = "/maintenance-page-url";
}
@vasilii-b
Copy link
Author

Adding the IPs to whitelist

Xnip2024-10-29_08-44-21

Adding the recv ACL rule:

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment