I have a magento2 web application which I need to enable maintenance mode excluding a specific IP. The following command did enable the maintenance mode without excluding my IP.

php bin/magento maintenance:enable --ip=

and I tried the following since the above command didn't work.

php bin/magento maintenance:allow-ips

var/.maintenance.ip does exist and it has my ip listed in it.


Are you by any chance using varnish or another reverse proxy? ie, it might be that your public IP does not get forwarded, and therefore cannot be recognised. Easiest check is the access logs on the webserver, see if you can see your own IP in there. Otherwise you'll have to implemented x-forwarded-for headers

| improve this answer | |
  • Thanks, @marcel-dumont. I am using CloudFlare. How do you suggest I expose my IP to my Magento application which is hosted on EC2? I have zero knowledge when it comes to this stuff. – TA3 Jun 18 '17 at 6:12
  • 1
    Have a look at support.cloudflare.com/hc/en-us/articles/… – Marcel Dumont Jun 18 '17 at 6:52

The typically maintenance mode will not work since your real IP is coming through as a forwarded IP due to the Haproxy/ Varnish setup. Try to create a maintenance page and directing all traffic, except for a few whitelisted IPs, to that page.

RewriteEngine on
RewriteCond %{HTTP:X-FORWARDED-FOR} !^123\.45\.67\.89
RewriteCond %{REQUEST_URI} !/maintenance.php$ [NC]
RewriteRule .* /maintenance.php [R=302,L]
| improve this answer | |

I can exclude ips from maintenance mode, by give below steps

1- php bin/magento maintenance:allow-ips MY_IP_ADDRESS

2- php bin/magento maintenance:enable

After running these two commands, I can see the maintenance mode is not enable for me.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.