采用源码安装
wget http://www.varnish-cache.org/releases/varnish-cache-2.1.4
cd ~/Desktop/2.1/varnish-cache
sudo ./configure --prefix=/usr/local/varnish
sudo make
sudo make install
安装ok
安装完成之后,开始做基本的配置
[email protected]:~$ vim /usr/local/etc/varnish/default.vcl
1 # backend default {
2 # .host = "127.0.0.1";
3 # .port = "801";
4 # }
5
6 去掉上面的注释
7
开始运行varnish
1 sudo varnishd -f /usr/local/etc/varnish/default.vcl -s malloc,1G -T 127.0.0.1:2000 -a 0.0.0.0:800
-f /usr/local/etc/varnish/default.vcl
表示varnish当前使用的配置文件
-s malloc,1G
表示给varnish分配1G内存存储空间
-T 127.0.0.1:2000
varnish 管理界面
-a 0.0.0.0:800
varnish监听800端口
如果出现:
varnishstat: error while loading shared libraries: libvarnish.so.1: cannot open shared object file: No such file or directory
执行:ldconfig,再重新启动
实例:
修改nginx配置
1 server {2 listen 80;
3 server_name *.bbs.xiazh.dev.example.com;
4 location / {
5 proxy_pass http://127.0.0.1:800; //反向代理,varnish监听此端口
6 }
7 }
8
9 server {
10 listen 801;
11 server_name *.bbs.xiazh.dev.example.com;
12 location / {
13 rewrite . /index.php last;
14 }
15 location /index.php {
16 internal;
17 fastcgi_pass 127.0.0.1:9000;
18 fastcgi_param SCRIPT_FILENAME /home/zhxia/projects/v2/app-aifang-bbs/index.php;
19 include /etc/nginx/fastcgi_params;
20 }
21 }
22
配置varnish
1 backend default {2 .host = "127.0.0.1";
3 .port = "801";
4 }
5
重新启动 varnish
1
2 sudo pkill varnished
3
4 sudo varnishd -f /usr/local/etc/varnish/default.vcl -s malloc,1G -T 127.0.0.1:2000 -a 0.0.0.0:800
声明: 此文观点不代表本站立场;转载须要保留原文链接;版权疑问请联系我们。