Changes between Version 8 and Version 9 of faq/shared-varnish-server
- Timestamp:
- Nov 18, 2012, 8:06:00 PM (11 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
faq/shared-varnish-server
v8 v9 1 '''NOTE: This documentation is out of date.''' 2 1 [[PageOutline]] 3 2 = Shared Varnish Caching = 4 3 If 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 [https://www.varnish-cache.org/about 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 dolores.mayfirst.org). … … 58 57 Our current varnish server is `dolores.mayfirst.org`. 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]. 59 58 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". 59 In your puppet configuration at '''puppet/modules/mayfirst/files/varnish''' you will see three important directories: 60 61 * backends 62 * mfpl-includes 63 * sites 64 65 === Ensure you have a backend === 66 The 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: 67 64 68 {{{ 69 0 ross@virilio:~/projects/puppet/modules/mayfirst/files/varnish/backends$ cat dorothy 70 backend dorothy { 71 .host = "216.66.23.40"; 72 .port = "80"; 73 } 74 0 ross@virilio:~/projects/puppet/modules/mayfirst/files/varnish/backends$ 75 }}} 76 77 === Adding your site vcl file === 78 The 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: 79 80 {{{ 81 0 ross@virilio:~/projects/puppet/modules/mayfirst/files/varnish/sites$ cat bdsmovement.vcl 82 # Drop any cookies sent to Wordpress. 65 83 sub vcl_recv { 66 if (req.http.host ~ "^(www\.)?chicagospring\.org" ) { 67 include "/etc/varnish/dolores/drupal-includes/drupal-recv.vcl"; 84 if (req.http.host ~ "^(www\.)?(bdsmovement)\.net" ) { 85 set req.backend = dorothy; 86 include "/etc/varnish/mfpl-includes/wordpress/recv.vcl"; 87 } 88 } 89 90 # Drop any cookies Wordpress tries to send back to the client. 91 sub vcl_fetch { 92 if (req.http.host ~ "^(www\.)?(bdsmovement)\.net" ) { 93 include "/etc/varnish/mfpl-includes/wordpress/fetch.vcl"; 94 } 95 } 96 0 ross@virilio:~/projects/puppet/modules/mayfirst/files/varnish/sites$ 97 }}} 98 99 ==== Modifying your site vcl file ==== 100 101 '''NOTE:''' In order for varnish to function properly you must include the following line in the `sub vcl_recv` directory. 102 103 `set req.backend = BACKEND_NAME` 104 105 You will need to create a file YOURSITE.vcl and make the necessary modifications. Specifically, you will need to make the req.http.host in both vcl_recv and vcl_fetch match the domain you're caching. 106 107 Also...based on your specific cms, you'll need to add mfpl-includes. 108 109 We 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. 110 111 === Modifying varnish server manifest === 112 113 The manifest of the specific varnish server will need to be modified. dolores.pp currently looks like this: 114 115 {{{ 116 class { "m_varnish": 117 listen_ip => "209.51.180.234", 118 backends => [ "cloudips", "kerr", "dorothy" ], 119 sites => [ "bofa.vcl", "occupychi.vcl", "chicagospring.vcl", "bdsmovement.vcl" ] 68 120 } 69 } 121 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": } 70 129 }}} 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.74 130 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 kerr.mayfirst.org. Hopefully we'll be able to support multiple guests soon. 131 You will need to make up to four modifications to this manifest: 76 132 77 '''NOTE:''' The above instructions should ultimately become a part of puppet or red. 133 1. Change the m_varnish backends line by adding `, "YOUR_BACKEND_NAME"` to the backends array (if it doesn't already exist). 134 2. Change the m_varnish sites line by adding `, "YOUR_SITENAME.vcl"` to the sites array. 135 3. Add the line `m_varnish::backend { "YOUR_BACKEND_NAME" }` if it doesn't already exist. 136 4. Add `m_varnish::site { "YOUR_SITENAME.vcl" }` 78 137 138 After 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! 139