| | 144 | == varnish == |
| | 145 | |
| | 146 | See ticket:224. |
| | 147 | |
| | 148 | Install Varnish 2.1 via the [http://www.varnish-cache.org/installation/debian varnish-cache.org repository]: |
| | 149 | |
| | 150 | {{{ |
| | 151 | curl http://repo.varnish-cache.org/debian/GPG-key.txt | apt-key add - |
| | 152 | aptitude install lsb-release |
| | 153 | echo "deb http://repo.varnish-cache.org/debian/ $(lsb_release -s -c) varnish-2.1" >> /etc/apt/sources.list.d/varnish.list |
| | 154 | aptitude update |
| | 155 | aptitude install varnish |
| | 156 | }}} |
| | 157 | |
| | 158 | Edit these things in the main config file, /etc/default/varnish : |
| | 159 | |
| | 160 | {{{ |
| | 161 | #DAEMON_OPTS="-a :6081 \ |
| | 162 | # -T localhost:6082 \ |
| | 163 | # -f /etc/varnish/default.vcl \ |
| | 164 | # -S /etc/varnish/secret \ |
| | 165 | # -s file,/var/lib/varnish/$INSTANCE/varnish_storage.bin,1G" |
| | 166 | |
| | 167 | DAEMON_OPTS="-a :80 \ |
| | 168 | -T localhost:81 \ |
| | 169 | -f /etc/varnish/default.vcl \ |
| | 170 | -S /etc/varnish/secret \ |
| | 171 | -s file,/var/lib/varnish/$INSTANCE/varnish_storage.bin,256M" |
| | 172 | }}} |
| | 173 | |
| | 174 | And in /etc/varnish/default.vcl : |
| | 175 | |
| | 176 | {{{ |
| | 177 | backend default { |
| | 178 | .host = "127.0.0.1"; |
| | 179 | .port = "8080"; |
| | 180 | .connect_timeout = 600s; |
| | 181 | .first_byte_timeout = 600s; |
| | 182 | .between_bytes_timeout = 600s; |
| | 183 | } |
| | 184 | acl purge { |
| | 185 | "localhost"; |
| | 186 | "127.0.0.1"; |
| | 187 | } |
| | 188 | |
| | 189 | # chris |
| | 190 | # http://drupal.org/node/1054886#purge |
| | 191 | sub vcl_recv { |
| | 192 | # remove all cookies |
| | 193 | unset req.http.Cookie; |
| | 194 | |
| | 195 | ## Pass cron jobs and server-status |
| | 196 | if (req.url ~ "cron.php") { |
| | 197 | return (pass); |
| | 198 | } |
| | 199 | if (req.url ~ ".*/server-status$") { |
| | 200 | return (pass); |
| | 201 | } |
| | 202 | |
| | 203 | # Normalize the Accept-Encoding header |
| | 204 | # as per: http://varnish-cache.org/wiki/FAQ/Compression |
| | 205 | if (req.http.Accept-Encoding) { |
| | 206 | if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") { |
| | 207 | # No point in compressing these |
| | 208 | remove req.http.Accept-Encoding; |
| | 209 | } elsif (req.http.Accept-Encoding ~ "gzip") { |
| | 210 | set req.http.Accept-Encoding = "gzip"; |
| | 211 | } elsif (req.http.Accept-Encoding ~ "deflate") { |
| | 212 | set req.http.Accept-Encoding = "deflate"; |
| | 213 | } else { |
| | 214 | # unkown algorithm |
| | 215 | remove req.http.Accept-Encoding; |
| | 216 | } |
| | 217 | } |
| | 218 | |
| | 219 | ## Default request checks |
| | 220 | if (req.request != "GET" && |
| | 221 | req.request != "HEAD" && |
| | 222 | req.request != "PUT" && |
| | 223 | req.request != "POST" && |
| | 224 | req.request != "TRACE" && |
| | 225 | req.request != "OPTIONS" && |
| | 226 | req.request != "DELETE" && |
| | 227 | req.request != "PURGE") { |
| | 228 | # Non-RFC2616 or CONNECT which is weird. |
| | 229 | return (pipe); |
| | 230 | } |
| | 231 | if (req.request != "GET" && req.request != "HEAD" && req.request != "PURGE") { |
| | 232 | # We only deal with GET, PURGE and HEAD by default |
| | 233 | return (pass); |
| | 234 | } |
| | 235 | |
| | 236 | # Check the incoming request type is "PURGE", not "GET" or "POST" |
| | 237 | if (req.request == "PURGE") { |
| | 238 | # Check if the ip coresponds with the acl purge |
| | 239 | if (!client.ip ~ purge) { |
| | 240 | # Return error code 405 (Forbidden) when not |
| | 241 | error 405 "Not allowed."; |
| | 242 | } |
| | 243 | # Purge all objects from cache that match the incoming url and host |
| | 244 | purge("req.url == " req.url " && req.http.host == " req.http.host); |
| | 245 | # Return a http error code 200 (Ok) |
| | 246 | error 200 "Purged."; |
| | 247 | } |
| | 248 | |
| | 249 | # Grace to allow varnish to serve content if backend is lagged |
| | 250 | #set obj.grace = 5m; |
| | 251 | } |
| | 252 | |
| | 253 | # remove all cookies |
| | 254 | # chris |
| | 255 | sub vcl_fetch { |
| | 256 | unset beresp.http.set-cookie; |
| | 257 | } |
| | 258 | |
| | 259 | # chris |
| | 260 | sub vcl_deliver { |
| | 261 | if (obj.hits > 0) { |
| | 262 | set resp.http.X-Varnish-Cache = "HIT"; |
| | 263 | } |
| | 264 | else { |
| | 265 | set resp.http.X-Varnish-Cache = "MISS"; |
| | 266 | } |
| | 267 | |
| | 268 | }}} |
| | 269 | |