这是关于Varnish3.03编译安装配置的笔记
安装
代码如下 | 复制代码 |
yum -y install gcc gcc-c++ file bison patch unzip mlocate flex wget diffutils automake autoconf kernel-devel gd cpp readline-devel openssl openssl-devel vim-minimal nano libjpeg libjpeg -devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel libidn libidn-devel openldap openldap-devel openldap-clients openldap-servers nss_ldap gettext gettext-devel expat-devel libcap libcap-devel libtool libtool- ltdl-devel pam-devel pcre-devel ncurses-devel subversion bind-utils rsync libxslt groff pkgconfig # compile Varnish-Cache /usr/sbin/groupadd -g 1000 -o -r varnish ln -s /usr/local/varnish/bin/varnish_reload_vcl /usr/bin/ chkconfig --add varnish |
配置
使用下面的代码来替换/etc/sysconfig/varnish中的内容,注意将下面代码中的121.199.13.169替换为你的vps的公网ip
代码如下 | 复制代码 |
# Configuration file for varnish # Maximum size of corefile (for ulimit -c). Default in Fedora is 0 # Set this to 1 to make init script reload try to switch vcl without restart. # This file contains 4 alternatives, please use only one. ## Alternative 1, Minimal configuration, no VCL ## Alternative 2, Configuration with VCL ## Alternative 3, Advanced configuration ## Alternative 4, Do It Yourself. See varnishd(1) for more information. |
使用下面的代码来替换/etc/varnish/default.vcl中的内容,如果/etc/varnish/default.vcl文件不存在,那就创建吧
代码如下 | 复制代码 |
# This is a basic VCL configuration file for varnish. See the vcl(7) if (req.http.Authorization) { if(req.url ~ ".(php)$" ){ if (req.request != "GET" && if (req.request != "GET" && req.request != "HEAD") { if (req.request == "GET" && req.url ~ "(?i).(js|css|jpg|jpeg|png|gif|ico|rar|gz|bz2|mp3|swf|flv)$") { sub vcl_fetch { sub vcl_deliver { |
最后,将nginx配置文件中所有的listen 80改成listen 127.0.0.1:80,改完之后重启nginx,然后执行如下命令就ok了~
代码如下 | 复制代码 |
service varnish restart |
说明:Varnish编译安装方法仿自诡谲(icodex.org),配置文件参照