Varnish删除http header相关信息

varnish删除http header相关信息

  1. sub vcl_deliver {
  2. remove resp.http.X-Varnish;
  3. remove resp.http.Via;
  4. remove resp.http.Age;
  5. remove resp.http.X-Powered-By;
  6. }

未删除前

  1. HTTP/1.1 200 OK
  2.   Server: Apache/2
  3.   X-Powered-By: PHP/5.2.17
  4.   Vary: Accept-Encoding,User-Agent
  5.   Content-Type: text/html; charset=UTF-8
  6.   Date: Thu, 05 Jul 2012 07:56:45 GMT
  7.   X-Varnish: 491720666
  8.   Age: 0
  9.   Via: 1.1 varnish
  10.   Connection: keep-alive
  11. Length: unspecified [text/html]
  12. Remote file exists and could contain further links,
  13. but recursion is disabled -- not retrieving.

删除后

  1. HTTP/1.1 200 OK
  2.   Server: Apache/2
  3.   Vary: Accept-Encoding,User-Agent
  4.   Content-Type: text/html; charset=UTF-8
  5.   Date: Thu, 05 Jul 2012 09:03:28 GMT
  6.   Connection: keep-alive
  7. Length: unspecified [text/html]
  8. Remote file exists and could contain further links,
  9. but recursion is disabled -- not retrieving.

Centos上安装部署varnish图片缓存服务器进行加速

centos安装配置varnish
如果再整合DNS,GeoIP,Nginx可就称得上私有的CDN服务了!

  1. [root@Centos ~]# yum install logrotate libgomp gcc cpp binutils kernel-headers glibc-headers glibc-devel -y #安装所需环境
  2. [root@Centos ~]# rpm --nosignature -i http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release-3.0-1.noarch.rpm #安装varnish
  3. [root@Centos ~]# yum install varnish -y #安装varnish
  4. [root@Centos ~]# service varnish start
  5. Starting Varnish Cache:                                    [  OK  ]
  6. [root@Centos ~]# cp /etc/sysconfig/varnish /etc/sysconfig/varnish.default #备份varnish默认的配置文件
  7. [root@Centos ~]# sed -i '/VARNISH_LISTEN_PORT=6081/s/6081/80/'  /etc/sysconfig/varnish #varnish默认端口为6081,改为80
  8. [root@Centos ~]# cp /etc/varnish/default.vcl /etc/varnish/default.vcl.default #备份varnish默认的配置文件
  9. [root@Centos ~]# vi /etc/varnish/default.vcl #修改backend的值
  10. backend default {
  11.   .host = "目标IP或域名";
  12.   .port = "目标端口";
  13. }
  14. [root@Centos ~]# cp /etc/sysconfig/varnish /etc/sysconfig/varnish.default
  15. [root@Centos ~]# vim /etc/sysconfig/varnish
  16. VARNISH_STORAGE_SIZE=50% #缓存文件大小
  17. [root@Centos ~]# more /etc/varnish/default.vcl #只缓存文本文件js等跟图片
  18. backend default {
  19.   .host = "baiqiuyi.com";
  20.   .port = "80";
  21. } 
  22. sub vcl_recv {
  23.     remove req.http.X-real-ip;
  24.     set req.http.X-real-ip = client.ip;
  25.     set req.http.X-Forwarded-For = client.ip;
  26. if (req.request == "GET" && req.url ~ "^/[^?]+\.(jpeg|jpg|png|gif|ico|swf|js|css|txt)(\?.*|)$") {
  27.     unset req.http.Cookie;
  28.     }
  29. if (req.url ~ "\.(png|gif|jpg|swf|css|js)$") {
  30. unset req.http.cookie;
  31. }
  32. }
  33. sub vcl_fetch {
  34. if (req.url ~ "\.(png|gif|jpg|swf|css|js)$") {
  35. unset beresp.http.set-cookie;
  36. }
  37. if (req.request == "GET" && req.url ~ "\.(js|css|jpg|png|gif|jpeg|ico)$") {
  38. set beresp.ttl = 365d;
  39. }
  40. }

以下为varnishi的linux版默认配置文件
Read more »

1 1