This topic discusses how you can create a custom maintenance page to display to users while your Magento application is being upgraded. Creating a custom page is optional but recommended because your site is accessible during part of the upgrade.
Creating a custom page to which to redirect users prevents any access to the site and also informs your users that the site is undergoing maintenance.
You must perform the tasks in this section as a user with root
privileges. Custom maintenance pages cannot be set while in developer mode.
To create a maintenance page and redirect to it, first create a maintenance page named:
<web server docroot>/maintenance.html
<magento_root>/maintenance.html
Add the following contents:
<!DOCTYPE html>
<html>
<head>
<title>Temporarily Offline</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
h1
{ font-size: 50px; }
body
{ text-align:center; font: 20px Helvetica, sans-serif; color: #333; }
</style>
</head>
<body>
# Temporarily offline
<p>We're down for a short time to perform maintenance on our site to give you the best possible experience. Check back soon!</p>
</body>
</html>
This section discusses how to create a custom maintenance page and how to redirect traffic to it.
The example in this section shows how to modify the following files, which is one way to set up your maintenance page:
/etc/apache2/sites-available/000-default.conf
/etc/apache2/sites-available/default
(Ubuntu), /etc/httpd/conf/httpd.conf
(CentOS)To redirect traffic to a custom maintenance page:
Update your Apache configuration to do the following:
The following example allowlists 192.0.2.110.
Add the following at the end of your Apache configuration file:
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^192\.0\.2\.110
RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
RewriteCond %{DOCUMENT_ROOT}/maintenance.enable -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /maintenance.html [R=503,L]
ErrorDocument 503 /maintenance.html
Header Set Cache-Control "max-age=0, no-store"
Restart Apache:
service httpd restart
service apache2 restart
Enter the following command:
touch <web server docroot>/maintenance.enable
Test your site to make sure it functions correctly.
After the upgrade is done, delete maintenance.enable
.
This section discusses how to create a custom maintenance page and how to redirect traffic to it.
To redirect traffic to a custom maintenance page:
Use a text editor to open the nginx configuration file that contains your server block.
Add the following to the server block (server
is shown for clarity only; don’t add a second server block).
The following allowlists IP address 192.0.2.110 and 192.0.2.115 on a system where Magento is installed in /var/www/html/magento2
:
server {
listen 80;
set $MAGE_ROOT /var/www/html/magento2;
set $maintenance off;
if (-f $MAGE_ROOT/maintenance.enable) {
set $maintenance on;
}
if ($remote_addr ~ (192.0.2.110|192.0.2.115)) {
set $maintenance off;
}
if ($maintenance = on) {
return 503;
}
location /maintenance {
}
error_page 503 @maintenance;
location @maintenance {
root $MAGE_ROOT;
rewrite ^(.*)$ /maintenance.html break;
}
include /var/www/html/magento2/nginx.conf;
}
Enter the following command:
touch <magento_root>/maintenance.enable
Reload the nginx configuration:
service nginx reload
Test your site to make sure it functions correctly.
After the upgrade is done, delete or rename maintenance.enable
Reload the nginx configuration:
service nginx reload