Varnish is a high performance open source HTTP accelerators, Norway’s largest newspaper Verdens Gang online (http://www.VG.no) using 3 Varnish instead of 12 sets of squid, and better performance than before.Varnish is a pretty powerful accelerators. Roy below show you how to install on CentOS Varnish to your WordPress blog up.
1, install Varnsih
Use SSH to log on your VPS, execute the following command to install the Varnish:
1 |
yum install varnish |
Then we start the Varnish:
1 |
/etc/init.d/varnish start |
Set to boot:
1 |
chkconfig –level 345 varnish on |
2, configuring Varnish
Open default.VCL:
1 |
nano /etc/varnish/default.vcl |
Confirm that the default default.VCL and matches the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# Back-End backend default { .host = "127.0.0.1"; .port = "80"; .connect_timeout = 60s; .first_byte_timeout = 10s; .between_bytes_timeout = 10s; } # Custom sub vcl_recv { remove req.http.X-Forwarded-For; set req.http.X-Forwarded-For = client.ip; if (req.url ~ "^/wp-(login|admin)") { return (pipe); } if (req.http.Cookie ~"(wp-postpass|wordpress_logged_in|comment_author_)") { return (pipe); } if (req.request == "POST") { return (pass); } if (req.http.Cache-Control ~ "no-cache") { return (pass); } if (req.http.Authorization) { return (pass); } if (req.url ~ "\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pd f|txt|tar|wav|bmp|rtf|js|flv|swf|htm|html)$") { unset req.http.Cookie; unset req.http.Accept-Encoding; unset req.http.Vary; return (lookup); } if (req.http.Accept-Encoding) { if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") { remove req.http.Accept-Encoding; } elsif (req.http.Accept-Encoding ~ "gzip") { set req.http.Accept-Encoding = "gzip"; } elsif (req.http.Accept-Encoding ~ "deflate") { set req.http.Accept-Encoding = "deflate"; } else { remove req.http.Accept-Encoding; } } if (req.backend.healthy) { set req.grace = 30s; } else { set req.grace = 1h; } unset req.http.Cookie; unset req.http.Vary; return (lookup); } sub vcl_fetch { set beresp.grace = 1h; unset beresp.http.set-cookie; if (req.url ~ "\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pd f|txt|tar|wav|bmp|rtf|js|flv|swf|htm|html)$") { set beresp.ttl = 24h; } else { set beresp.ttl = 5m; } return (deliver); } sub vcl_deliver { if(obj.hits > 0) { set resp.http.X-Cache = "HIT"; } else { set resp.http.X-Cache = "MISS"; } set resp.http.Cache-Control = "private"; set resp.http.Pragma = "private"; remove resp.http.X-Varnish; remove resp.http.Via; remove resp.http.Age; remove resp.http.Server; remove resp.http.X-Powered-By; } sub vcl_pipe { set bereq.http.connection = "close"; } |
Restart Varnish for its entry into force:
1 |
/etc/init.d/varnish restart |