varnish

Varnishing Polls

Accepting votes from anonymous users on Drupal polls is complicated when you use caching. By using Edge Side Includes (ESI), you can dynamically load some parts of a Drupal page while caching the rest of it. The addition of the Poll Enhancements module allows multiple anonymous users to vote on polls by using cookies to track who has voted.

Edge Side Includes integration
The ESI module includes two Varnish VCL files (located in the docs directory of the module:

  • docs/esi_blocks.vcl - custom sub-routines to handle ESI-block integration.
    Copy this file to the Varnish config directory, /usr/local/etc/varnish/

Purging the Varnish Cache

Various ways for removing entries from your Varnish cache

Technology:

Stop image bandwidth theft

Prevent other websites from stealing your bandwidth by including your images in their pages.

  • Apache
    This example services up a different image instead:

    RewriteEngine On
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.com [NC]
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} ^http://.*$
    RewriteRule \.(jpe?g|gif|bmp|png)$ /media/nohotlinks.png [L]
  • Lighttpd
    $HTTP["referer"] !~ "^(http://example\.com|http://www\.example\.com)" {
      $HTTP["referer"] != "" {
        url.access-deny = ( ".jpg", ".jpeg", ".png", ".gif", ".pdf" )
      }
    }

Varnish Configuration

Extra Header Information
Add some extra HTTP header details to tell whether the page you are getting came from the Varnish cache by adding this snippet to /usr/local/etc/varnish/drupal.vcl:

sub vcl_deliver {
  #add cache hit data
  if (obj.hits > 0) {
    #if hit add hit count
    set resp.http.X-Varnish-Cache = "HIT";
    set resp.http.X-Cache-Hits = obj.hits;
  } else {
    set resp.http.X-Varnish-Cache = "MISS";
  }
}

Grace for Misbehaving Backends
http://varnish-cache.org/trac/wiki/VCLExampleGrace

Technology:

Varnish Module

The Varnish HTTP Accelerator Integration module provides integration between your Drupal site and Varnish. This module provides admin-socket integration which allows Drupal to dynamically invalidate cache entries, and also lets you query the Varnish admin interface for status, etc.

Requirements

  • PHP must be compiled with --enable-sockets
  • Edit /service/varnish/run and add -T 127.0.0.1:6082 to start the admin interface on the default module port.

Technology:

Logging

Running Varnish in front of your web server will mess up your normal Apache log files as the majority of traffic will be served from the cache. Varnish normally writes its log information to memory, but includes the varnishncsa program which displays the data in the Apache/NCSA combined format and can write that data to a file.

varnishncsa Startup
With Varnish installed from source, daemontools is an easy way to run the logging daemon. If you haven't already, install daemontools.

Create a directory for the varnishncsa service:

mkdir -m 1755 /var/service/varnishncsa
cd /var/service/varnishncsa

Create the run script and make it executable:

echo '#!/bin/sh' > run
echo 'exec 2>&1' >> run
echo 'exec varnishncsa' >> run
chmod 755 run

Technology:

Varnish

Accelerate your Drupal/Pressflow site using Varnish

The primary reason for switching to Pressflow is to use an HTTP accelerator such as Varnish
Apache Configuration
Adjust your Apache configuration to server the Drupal site on port 8080. Edit your Apache conf file and add:

Listen 8080
NameVirtualHost *:8080

Restart Apache and make sure you can access your site on that port.

Varnish Configuration

Varnish

Installation
In addition to the basic development tools, there's a few other dependencies:

yum install ncurses-devel pcre-devel libtool

Download the Varnish source code:

cd /extra/src
wget http://repo.varnish-cache.org/source/varnish-2.1.5.tar.gz
tar zxf varnish-2.1.5.tar.gz
cd varnish-2.1.5

Configure and build it:

sh autogen.sh
./configure
make

If you want, you can run the tests before installing:

Technology:

Subscribe to RSS - varnish

Recent Updates

  • 5 days 1 hour ago
    1.27.2 update
  • 2 weeks 2 days ago
    Drupal 10/11 config
  • 2 weeks 3 days ago
  • PHP
    2 weeks 3 days ago
    PHP 8.3.11 and AlmaLinux
  • 2 weeks 4 days ago
    New version of Pound