Install varnish in centos
- 1. Download the installation package and modify the file name.
- Wgethttp: // sourceforge.net/projects/varnish/files/latest/download
- Tarzxvfdownload
- Cdvarnish-2.1.3
- 2. Install related components pcre
- Yuminstallpcre
- 3. Set Environment Variables
- ExportPKG_CONFIG_PATH =/usr/local/lib/pkgconfig
- 4. Configuration
- ./Configure -- prefix =/usr/local/varnish -- enable-dependency-trackin -- enable-debugging-symbols -- enable-developer-warnings
- 5. Compile and install
- Make & makeinstall
- 6. Start
- .../// Sbin/varnishd-f/usr/local/varnish/etc/varnish. vcl-sfile,/var/varnish_cache, 1G-T127.0.0.1: 2000-a0.0.0.0: 9001
Sample Configuration
[Plain] view plaincopy
- [Root @ localhostvarnish] # catvarnish. vcl
- Backendcqserver {
- . Host = "192.168.0.1 ";
- . Port = "5007 ";
- . Connect_timeout = 20 s;
- }
- Aclpurge {
- "Localhost ";
- "127.0.0.1 ";
- "192.168.1.0"/24;
- }
- Subvcl_recv {
- If (req. request = "PURGE "){
- If (! Client. ip ~ Purge ){
- Error405 "Notallowed .";
- }
- Return (lookup );
- }
- If (req. http. host ~ "^192 "){
- Setreq. backend = cqserver;
- If (req. request! = "GET" & req. request! = "HEAD "){
- Return (pipe );
- }
- Else {
- Return (lookup );
- }
- }
- Else {
- Error404 "caoqingCacheServer ";
- Return (lookup );
- }
- }
- Subvcl_hit {
- If (req. request = "PURGE "){
- Setobj. ttl = 0 s;
- Error200 "Purged .";
- }
- }
- Subvcl_deliver {
- If (obj. hits> 0 ){
- Setresp. http. X-Cache = "HIT ";
- } Else {
- Setresp. http. X-Cache = "MISS ";
- }
- }
- Subvcl_miss {
- If (req. request = "PURGE "){
- Error404 "Notincache .";
- }
- }