热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Varnish的基本安装方法

采用源码安装wgethttp://www.varnish-cache.org/releases/varnish-cache-2.1.4cd~/Desktop/2.1/varnish-cachesudo./configure--prefix/usr/local/varnishsudomakesudomakeinstall

采用源码安装

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

 

安装完成之后,开始做基本的配置

 

zhxia@zhxia-desktop:~$ vim /usr/local/etc/varnish/default.vcl

 

 

1 # backend default {
2 #     .host = "127.0.0.1";
3 #     .port = "801";
4 # }

6 去掉上面的注释

开始运行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  }

 

重新启动 varnish

 


2 sudo pkill varnished

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

 

 


推荐阅读
author-avatar
mobiledu2502926597
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有