1. Home
  2. Magento 2 Guides
  3. Enabling the Varnish FPC in Magento 2

Enabling the Varnish FPC in Magento 2

Magento 2 was built with Varnish in mind. While the built-in FPC is ok for development, any live or production site should be using the Varnish FPC for maximum performance and concurrency (if you have doubts, see our siege test comparisons of our Demo Servers.  Fortunately, our panel and software stack includes Varnish which can be enabled per vhost so you can run Magento 2 with Varnish alongside non-Varnished sites with ease.

Follow these steps to enable the Varnish FPC

  1. Log into your Magento 2 admin, then open Stores->Configuration
  2. On the next page, go to Advanced->System then expand the Full Page Cache section.  You should see this screen.  It should show the built-in FPC is enabled.
  3. Adjust the settings if needed to match the screenshot below. The defaults should be acceptable, but otherwise, the backend port must be 8080
  4. Export the VCL for Varnish 4, save this file to your local computer, you will need to upload it later.
  5. Confirm the settings are correct, with the Caching Application set to Varnish Caching, then click the orange Save Config button 
  6. Log into your MageMojo server via FTP or SFTP or other preferred file upload method.  Upload the Varnish VCL to the Magento web root in the var directory ({{magentoroot}}/var/) It should be named default.vcl. You do not need to edit this file in any way, unless you are using Magento version 2.2 and above. For Magento 2.2 ( While using the Magento 2.1 template in MHM ) you will need to edit the following line:.probe = {
    .url = /pub/health_check.php;change to

    .probe = {
    .url = /health_check.php;

    MageMojo has already accounted for the /pub directory, so the path is incorrect in this file. This is a “health check” that is tested by Varnish before it will continue requests.

  7. Open Mojo Host Manager for your server and find the vhost/website configuration.
  8. Click the Advanced tab; you should see a configuration form similar to the one below.
  9. Enable Varnish on port 6082 (if you have other Varnish installations you should select a different port)
  10. Click the green Save button to apply the configuration.  The varnish daemon will be started on port 6082 and use the default.vcl uploaded to your Magento install.  Our Varnish configuration automatically detects VCLs in var/ for both Magento 1 and 2 and applies them to the vhost set to that web root when Varnish is enabled.
  11. Magento 2 is now using Varnish FPC, you can confirm via utilities like varnishtop or checking the time to first byte for your site, it should be much lower now.
  12. Configure Magento 2 to purge Varnish when the cache is cleared


Offloading SSL

Normally, SSL pages will not go through Varnish, this is typically fine for checkouts etc, if you will using all HTTPS across a site, then a special include must be added to the vhost to allow this.

SSL OFFLOADED should also be set to 1/yes in Magento itself.

For Nginx, add this via the Vhost Level Configuration Includes

For Apache, add this via the Vhost Level Configuration Includes

Additional Notes

When a Varnish daemon is launched on a MageMojo server, it launches on a particular port as selected for the vhost and automatically looks for a VCL file in var/ of the vhost webroot. If you are in the shell you will see this via ps aux  –

Varnish FPC Purging

See  Purge the Varnish FPC

Updated on September 4, 2018

Was this article helpful?

Related Articles