Configuration of the varnish cache server

Source: Internet
Author: User
Tags varnish
: Bytes

: Http://pkgs.fedoraproject.org/repo/pkgs/varnish/varnish-2.1.3.tar.gz/357d99a760de173d841ac37bf2052be8/varnish-2.1.3.tar.gz

1. install varnish

# Tar zxvf varnish-2.1.3.tar.gz

# Cdvarnish-2.1.3

#/Configure? Prefix =/opt/varnish

# Make & make install

II. configure an instance

# Vi/opt/varnish/etc/varnish/test. vcl

Backend bbs {
. Host = "202.105.182.55 ";
. Port = "80 ";}


Acl local {"localhost ";
"192.168.2.4 ";
}



Sub vcl_recv {
If (req. request = "PURGE "){
If (! Client. ip ~ Local ){
Error 405 "Not Allowed .";
Return (lookup );
}
}

If (req. request = "GET" & req. url ~ "\. (Jpg | png | gif | swf | jpeg | ico) $ "){
Unset req. http. cookie;
}
If (req. http. x-forwarded-){
Set req. http. X-Forwarded-For =
Req. http. X-Forwarded-For "," client. ip;
} Else {
Set req. http. X-Forwarded-For = client. ip;
}
If (req. request! = "GET "&&
Req. request! = "HEAD "&&
Req. request! = "PUT "&&
Req. request! = "POST "&&
Req. request! = "TRACE "&&
Req. request! = "OPTIONS "&&
Req. request! = "DELETE "){

Return (pipe );
}
If (req. request! = "GET" & req. request! = "HEAD "){
Return (pass );
}
If (req. http. Authorization | req. http. Cookie ){
Return (pass );
}
If (req. request = "GET" & req. url ~ "\. (Php) ($ | \?) "){
Return (pass );
}
Return (lookup );
}
Sub vcl_pipe {return (pipe );
}
Sub vcl_pass {return (pass );
}
Sub vcl_hash {
Set req. hash + = req. url;
If (req. http. host ){
Set req. hash + = req. http. host;
} Else {
Set req. hash + = server. ip;
}
Return (hash );
}
Sub vcl_hit {
If (! Obj. cacheable ){
Return (pass );
}
Return (deliver );
}
Sub vcl_miss {
Return (fetch );
}

Sub vcl_fetch {
If (! Beresp. cacheable ){
Return (pass );
}
If (beresp. http. Set-Cookie ){
Return (pass );

}
If (beresp. http. Set-Cookie ){
Return (pass );
}
If (beresp. http. Pragma ~ "No-cache" |
Beresp. http. Cache-Control ~ "No-cache" |
Beresp. http. Cache-Control ~ "Private "){
Return (pass );
}
If (req. request = "GET" & req. url ~ "\. (Js | css | mp3 | jpg | png | gif | swf | jpeg | ico) $ ")
{
Set beresp. ttl = 7d;
}
Return (deliver );
}
Sub vcl_deliver {set resp. http. x-hits = obj. hits;
If (obj. hits> 0 ){
Set resp. http. X-Cache = "HIT cqtel-bbs ";
} Else {
Set resp. http. X-Cache = "MISS cqtel-bbs ";
}
}


Sub vcl_error {
Set obj. http. Content-Type = "text/html; charset = utf-8 ";
Synthetic {"

Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>


"} Obj. status" "obj. response {"


Error "} obj. status" "obj. response {"

"} Obj. response {"


Guru Meditation:

XID: "} req. xid {"




Bbs cache server


"};
Return (deliver );
}

Start varnish:

# Ulimit-shn51200

# Useradd-s/sbin/nologin www

#/Opt/varnish/sbin/varnishd-u www-g www-f/opt/varnish/etc/varnish/test. vcl-a 192.168.2.4: 80-s file,/data/varnish_cache/varnish_cache.data, 1G-w 1024,5100, 10-t 3600-T 192.168.2.4: 3500

Parameter:-u used for running

-G

-F varnish configuration file

-A: bind the IP address and port

-S varnish cache file location and size

-W minimum, maximum thread and timeout

-T varnish management Port, mainly used to clear the cache

-S file,/data/varnish_cache/varnish_cache.data, 1 GB cache Directory. the 32-bit system cannot exceed 2 GB. we recommend that you use a 64-bit system and a faster speed, changing this directory to the memory cache will be faster, and the larger the memory, the better.

Stop varnish:

# Pkill varnishd


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.