Changes between Version 8 and Version 9 of faq/shared-varnish-server

Nov 18, 2012, 3:06:00 PM (8 years ago)



  • faq/shared-varnish-server

    v8 v9  
    1 '''NOTE: This documentation is out of date.'''
    32= Shared Varnish Caching =
    43If you find that your site runs slowly and you've turned on all the CMS specific caching features available to you, it might be time to use our shared [ varnish server].  Varnish helps manage higher traffic websites by creating a cache of all the previous page loads and serving them up with a minimal amount of processing.  In order to hook into our shared varnish instance, you'll need to make some changes to your DNS entries, and a support team member will need to add a file to our varnish server (currently
    5857Our current varnish server is ``.  A support team member needs to make the following configuration changes for each new hosting order. If you need these changes made and you aren't a member of the support team, please [/newticket open a new ticket explaining what you need to happen].
    60  * In your puppet configuration '''puppet/modules/mayfirst/files/varnish'''
    61  * Create a new vcl file for the domain, i.e. `/etc/varnish/VARNISH_SERVER_NAME/domain-name.vcl`
    62  * Copy the format of a current vcl file, depending on the CMS.  The include lines will vary depending on the CMS.  We currently have default varnish files for wordpress and drupal.
    63  * Make the needed changes to the file which should be the line that references the domain, make sure the domain is accurate. In the example below "occupychicago\.org" should read "YOUR_DOMAIN_NAME\.org".
     59In your puppet configuration at '''puppet/modules/mayfirst/files/varnish''' you will see three important directories:
     61 * backends
     62 * mfpl-includes
     63 * sites
     65 === Ensure you have a backend ===
     66The first step is to check that the virtual server on which the desired varnish site has a backend.  If it does not you will need to create one, the dorothy backend looks like this:
     690 ross@virilio:~/projects/puppet/modules/mayfirst/files/varnish/backends$ cat dorothy
     70backend dorothy {
     71    .host = "";
     72    .port = "80";
     740 ross@virilio:~/projects/puppet/modules/mayfirst/files/varnish/backends$
     77=== Adding your site vcl file ===
     78The backend tells varnish which IP Address to listen on.  Once you've established that you have a backend for your server, you can add your specific site from the sites directory.  Each domain requires it's own site file, which looks something like this:
     810 ross@virilio:~/projects/puppet/modules/mayfirst/files/varnish/sites$ cat bdsmovement.vcl
     82# Drop any cookies sent to Wordpress.
    6583sub vcl_recv {
    66   if ( ~ "^(www\.)?chicagospring\.org" ) {
    67     include "/etc/varnish/dolores/drupal-includes/drupal-recv.vcl";
     84    if ( ~ "^(www\.)?(bdsmovement)\.net" ) {
     85        set req.backend = dorothy;
     86        include "/etc/varnish/mfpl-includes/wordpress/recv.vcl";
     87    }
     90# Drop any cookies Wordpress tries to send back to the client.
     91sub vcl_fetch {
     92    if ( ~ "^(www\.)?(bdsmovement)\.net" ) {
     93        include "/etc/varnish/mfpl-includes/wordpress/fetch.vcl";
     94    }
     960 ross@virilio:~/projects/puppet/modules/mayfirst/files/varnish/sites$
     99==== Modifying your site vcl file ====
     101'''NOTE:''' In order for varnish to function properly you must include the following line in the `sub vcl_recv` directory.
     103`set req.backend = BACKEND_NAME`
     105You will need to create a file YOURSITE.vcl and make the necessary modifications.  Specifically, you will need to make the in both vcl_recv and vcl_fetch match the domain you're caching.
     107Also...based on your specific cms, you'll need to add mfpl-includes.
     109We have both standard wordpress and drupal caching components in the directory mfpl-includes.  For most configurations you can simply use `/etc/varnish/mfpl-include/(wordpress|drupal).recv.vcl` in the vcl_recv directive and `/etc/varnish/mfpl-include/(wordpress|drupal).fetch.vcl` in the vcl_fetch directive.
     111=== Modifying varnish server manifest ===
     113The manifest of the specific varnish server will need to be modified.  dolores.pp currently looks like this:
     116  class { "m_varnish":
     117    listen_ip => "",
     118    backends => [ "cloudips", "kerr", "dorothy" ],
     119    sites => [ "bofa.vcl", "occupychi.vcl", "chicagospring.vcl", "bdsmovement.vcl" ]
    68120  }
    69 }
     122  m_varnish::backend { "dorothy": }
     123  m_varnish::backend { "cloudips": }
     124  m_varnish::backend { "kerr": }
     125  m_varnish::site { "bofa.vcl": }
     126  m_varnish::site { "occupychi.vcl": }
     127  m_varnish::site { "chicagospring.vcl": }
     128  m_varnish::site { "bdsmovement.vcl": }
    71  * Add an include line in `/etc/varnish/VARNISH_SERVER_NAME/vhosts-list.vcl` for the file you created above.
    72  * When your changes are complete commit them to the repository and do git push SERVER_NAME or freepuppet-helper gp:SERVER_NAME.
    73  * Make sure to follow the puppet output for any errors.
    75 '''NOTE 0:''' We currently have not worked out a way for varnish to work across multiple servers.  So the above method will only work with a single guest server, at the time of this writing  Hopefully we'll be able to support multiple guests soon.
     131You will need to make up to four modifications to this manifest:
    77 '''NOTE:''' The above instructions should ultimately become a part of puppet or red.
     1331. Change the m_varnish backends line by adding `, "YOUR_BACKEND_NAME"` to the backends array (if it doesn't already exist).
     1342. Change the m_varnish sites line by adding `, "YOUR_SITENAME.vcl"` to the sites array.
     1353. Add the line `m_varnish::backend { "YOUR_BACKEND_NAME" }` if it doesn't already exist.
     1364. Add `m_varnish::site { "YOUR_SITENAME.vcl" }`
     138After pushing your changes to puppet, make sure varnish restarts without error and ensure the DNS changes have been made to point to the varnish server's (dolores) IP Address.  Then enjoy the benefits of sharing varnish!