Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

DrupalCon Barcelona 2015

535 views

Published on

The presentation focuses on providing information how to setup hosting servers to use Nginx/Varnish for caching Drupal websites. It features the SiteGround SuperCacher and gives valuable information about how reverse proxies work and how to make a Drupal 7/8 website cache-able by Nginx and Varnish.

Published in: Technology
  • Be the first to comment

DrupalCon Barcelona 2015

  1. 1. NGINX/VARNISH FULL PAGE CACHING FOR DRUPAL DANIEL KANCHEV Twitter: @dvkanchev SITEGROUND.COM
  2. 2. WHY YOU NEED FULL PAGE CACHING ?
  3. 3. CODE RED WHILE OUT AT LUNCH
  4. 4. WHAT EXACTLY IS FULL PAGE CACHING?
  5. 5. Pep
  6. 6. Pep
  7. 7. Pep
  8. 8. Pep Apache
  9. 9. Pep Apache PHP
  10. 10. Pep Apache PHP MySQL
  11. 11. Pep Apache PHP MySQL HTML
  12. 12. Pep CACHED
 HTML
  13. 13. Pep CACHED HTML
  14. 14. DRUPAL 7 Pros:
 • Full page caching is available Cons:
 • It is not Nginx/Varnish friendly • It does not offer easy cache invalidation • Not enabled by default
  15. 15. DRUPAL 8 Pros:
 • Reverse proxy (Nginx/Varnish) friendly full page caching • Easy to invalidate • Enabled by default Cons:
 • None I can think of :)
  16. 16. Pep Apache
 PHP
 MySQL Nginx Varnish Reverse Proxy Backend Server REVERSE PROXY?
  17. 17. DRUPAL 7 + VARNISH/NGINX • Install Varnish/Nginx • Create a configuration file for Varnish/Nginx • Install a plugin which will invalidate the cache
  18. 18. DRUPAL 7 + VARNISH/NGINX • Install Varnish/Nginx • Create a configuration file for Varnish/Nginx • Install a plugin which will invalidate the cache
  19. 19. SITEGROUND SOLUTION • Our own plugin for Drupal 7 - Cache auto invalidation - URL cache blacklisting • Custom Nginx configuration - Suitable for shared hosting servers - Cached copies are kept in RAM
  20. 20. map $http_cookie $nocache_cookie_drupal { ~*(^|;s*)(drupalSGCacheBypass=1)(;|$) 1; ~*Drupal.visitor.name 1; default 0; } map $http_cookie $skipcache_cookie_drupal { ~*(^|;s*)(drupalSGCacheBypass=1)(;|$) 1; ~*Drupal.visitor.name 1; default 0; } map $request_uri $nocache_uri_drupal { ~*^/admin/content/backup_migrate/export 1; ~*^/(status.php$|update.php|install.php) 1; ~*^/(admin|admin/.*$|user|user/.*$|info/.*$|flag/.*$|ajax/.*$|aha/.*$) 1; default 0; } map $request_uri $skipcache_uri_drupal { ~*^/admin/content/backup_migrate/export 1; ~*^/(status.php$|update.php|install.php) 1; ~*^/(admin|admin/.*$|user|user/.*$|info/.*$|flag/.*$|ajax/.*$|aha/.*$) 1; default 0; } NGINX CONF
  21. 21. DRUPAL 7 PLUGIN function supercacher_page_alter(&$page) { if ( !variable_get('supercacher_enabled', 0) || supercacher_isUrlBlacklisted()) { drupal_add_http_header('X-Cache-Enabled', 'False'); return; } drupal_add_http_header('X-Cache-Enabled', 'True'); // Logged In Users if ( user_is_logged_in() || ( ! empty( $_POST['op'] ) && 'Log In' === $_POST['op'] ) ) { setcookie( 'drupalSGCacheBypass', 1, time() + 100 * 60, '/' ); } elseif ( !user_is_logged_in() && (!isset($_COOKIE['drupalSGCacheBypass']) || ($_COOKIE['drupalSGCacheBypass'] != 1))) { setcookie( 'drupalSGCacheBypass', 0, time() - 3600, '/' ); } //dirty hacks: if (isset($_POST['form_id']) && $_POST['form_id'] == 'system_theme_settings') supercacher_purge(); }
  22. 22. SOME MORE CODE FROM THE DRUPAL 7 PLUGIN
  23. 23. OUR PLUGIN http://download.siteground.com/drupal/drupalSGCache.zip
  24. 24. ROADMAP FOR OUR SUPERCACHER • Support For Drupal 8 • Use cache tags/meta data for invalidation • Implement user based caching
  25. 25. RESOURCES • https://groups.drupal.org/nginx • http://wiki.nginx.org/Drupal • https://www.drupal.org/node/1054886 • https://www.drupal.org/project/varnish • http://wimleers.com/blog/drupal-8-page-caching-enabled-by- default • http://wimleers.com/blog/renderviz-prototype
  26. 26. FRIDAY SPRINTS • Sprint with the Community on Friday. • We have tasks for every skillset. • Mentors are available for new contributors. • An optional Friday morning workshop for first-time sprinters will help you get set up. • Follow @drupalmentoring.

×