-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Magento 2 .maintenance.ip file is not working behind Varnish + Nginx #8975
Comments
should be fixed in this PR: #7864 |
Thanks for sharing your PR. @behnamshayani Indeed, this PR will fix the first part of this issue but not the second. If a customer access to my website in maintenance mode, Varnish will cache some pages. Magento needs to communicate with Varnish in order not to cache pages only for authorized customer during maintenance. Is it clear enough ? |
Would you suggest that when entering maintenance mode that varnish is informed by some message that temporarily disables caching? That would be ideal. The alternatives are:
|
I faced the same issues as Franck with a similar configuration, except I'm running Apache 2.4 on CentOS 7. After several days and much gnashing of teeth, I came up with solutions that appear to work for me (ymmv). In the hopes of saving someone else some time... To pass the real customer IP address to the PHP scripts: I added the following lines to my Apache config file (which in my case is httpd.conf):
Then restarted Apache. To bypass the Varnish cache while in maintenance mode: I added the following line to my Apache config file:
Then restarted Apache and Varnish (which appears to be an easy way to clear the cache). To re-enable the Varnish cache after leaving maintenance mode: I commented out the line above that I added to my Apache config file:
Then restarted Apache. |
Hmm. It seems that I sometimes need to clear the cache with the Magento CLI as well...
Don't know if other cache types might be relevant. |
@franckgarnier21, thank you for your report. |
Hi @ihor-sviziev. Thank you for working on this issue.
|
Hi @franckgarnier21, |
Hi @franckgarnier21, |
@cmuench Thanks for pointing me out the great solution for this current problem. And indeed, I don't know why this issue was closed |
Preconditions
Magento 2.1.X
Varnish
Nginx
Test on a real webserver, not in local
Steps to reproduce
Browse your website before in order to put some page in Varnish cache
Enable maintenance mode via ssh , once in the application folder
php bin/magento maintenance:enable --ip=xxx.xxx.xxx.xxx
different from local IP 127.0.0.1 which works.
Expected result
Actual result
Cause 1
Varnish forward the real customer IP through the X-Forwarded-For header.
Mange 2 bootstrap do not check this header but
$isOn = $this->maintenance->isOn(isset($this->server['REMOTE_ADDR']) ? $this->server['REMOTE_ADDR'] : '');
Workaround 1
Update Nginx configuration in order to set the real customer IP
Cause 2
If a user access the website with an allowed IP, Varnish will cache these pages. So other customer with forbidden IPs will be able to access the website which is supposed to be in maintenance!
Workaround 2
Magento needs to add some response header in order to communicate with Varnish that the page is currently in maintenance mode and should not be cached or not be server for other IPs.
Related issues
#4219
#7596
The text was updated successfully, but these errors were encountered: