WordPress在CentOS伺服器下如何安裝Varnish加速

來源:互聯網
上載者:User

Varnish是一款高效能的開源HTTP加速器,挪威最大的線上報紙Verdens Gang (http://www.vg.no) 使用3台Varnish代替了原來的12台squid,效能居然比以前更好。可見Varnish是一個相當強大的加速器。下面羅伊給大家介紹如何在 CentOS上安裝Varnish來給你的WordPress部落格加速。

1,安裝Varnsih

使用SSH登入你的VPS,執行下面的命令來安裝Varnish:

yum install varnish

然後我們啟動Varnish:

/etc/init.d/varnish start

設定為開機啟動:

chkconfig –level 345 varnish on

2,配置Varnish

開啟default.vcl:

nano /etc/varnish/default.vcl

確認預設的default.vcl和下面的代碼相匹配:

# 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"; }

 

重啟Varnish使其生效: /etc/init.d/varnish restart

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.