浏览文章

文章信息

Varnish6 使用Basicauth验证CentOS7/Ubuntu18 12138


1)安装依赖项

apt-get install -y apt-transport-https \&& apt-get install -y git-core zlib1g-dev automake build-essential libtool libssl-dev \libreadline-dev libyaml-dev libsqlite3-dev ncurses-dev sqlite3 libxml2-dev libxslt1-dev \libpcre3-dev libcurl4-openssl-dev python-docutils python-software-properties libvarnishapi-dev

2)添加清varnish源

curl https://repo.varnish-cache.org/GPG-key.txt | apt-key add -printf "deb https://repo.varnish-cache.org/ubuntu/ trusty varnish-4.1 \ndeb-src https://repo.varnish-cache.org/ubuntu/ trusty varnish-4.1" >> /etc/apt/sources.list.d/varnish-cache.list && apt-get update

3)安装Varnish 4.1

apt-get install -qy varnish

4)获取Varnish源码并进行编译

apt-get source varnish & rm *.diff.gz *.dsc *.tar.gz \&& mv varnish* varnish-source && cd varnish-source && ./autogen.sh && ./configure --prefix=/usr/sbin && make

5)获取Varnish基本身份验证VMOD并将其编译

CentOS7:yum install varnish-devel.x86_64

git clone http://git.gnu.org.ua/cgit/vmod-basicauth.git && cd vmod-basicauth && git clone http://git.gnu.org.ua/repo/acvmod.git && ./bootstrap && ./configure VARNISHSRC=/varnish-source VMODDIR=/usr/lib64/varnish/vmods/ && make && make install && make check

6)更新default.vcl

sub vcl_recv {if (!basicauth.match("/etc/varnish/htpasswd",  req.http.Authorization)) {
            return(synth(401, "Authentication required"));
    }}sub vcl_synth {
  if (resp.status == 401) {
        set resp.http.WWW-Authenticate = "Basic";
  }}


原创