Configuring Varnish for Magento·续2
If you’re using Nginx instead, please run the following command to restart your web server:
sudo systemctl restart nginx
And finally, you’ll have to run the following command to restart Varnish:
sudo systemctl restart varnish
After the restart, your web server will accept traffic on port 8080, Varnish will handle HTTP traffic on port 80. The restart will also ensure the right VCL file is loaded, which will ensure that requests for your Magento store can be properly cached.
6. Making cache purges work#
By default Magento will send HTTP PURGE requests to Varnish using the base url. This is not done through the loopback interface but through one of the main network interfaces. The IP address the purge requests originate from doesn’t match localhost and will cause the purge to fail.
Assuming Varnish is installed on the same machine as Magento, listening on port 80, the following command can be executed to make Magento aware of Varnish:
bin/magento setup:config:set --http-cache-hosts=localhost
This will ensure the loopback interface is used and the incoming requests pass the ACL, which is configured to only allow connections coming from localhost.
If Varnish is located on another server or another port, you have to set the --http-cache-hosts accordingly. Click here for more information.
7. Flushing the cache#
In the final step we will flush all Magento caches to ensure a consistent state:
bin/magento cache:flush
