LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-02-2012, 12:07 PM   #1
diabloo
LQ Newbie
 
Registered: Apr 2012
Posts: 1

Rep: Reputation: Disabled
varnish misses for images instead of hits


I have been attempting to cache only images with varnish. However, I seem to get misses based on what I see from varnishlog. Is there anything wrong with my varnish configuration?

Quote:
12 RxHeader c Connection: close
12 VCL_call c recv lookup
12 VCL_call c hash
12 Hash c /images/pg/navarrow.png
12 Hash c www.mydomain.com
12 VCL_return c hash
12 VCL_call c miss fetch

I see miss fetch all the time for my images.


/etc/varnish/default.vcl
Quote:
backend default {
.host = "127.0.0.1";
.port = "8080";
.connect_timeout = 60s;
.first_byte_timeout = 600s;
.between_bytes_timeout = 60s;
}

sub vcl_recv {

if (req.url ~ "\.(png|gif|jpg|swf|ico)$") { return (lookup); }

if (req.url ~ "(?i)\.(js|css)(\?[a-z0-9]+)?$") { return (pass); }

if (req.http.X-Forwarded-For) {
set req.http.X-Real-IP = regsub(req.http.X-Forwarded-For, ",*", "");
remove req.http.X-Forwarded-For;
}

if (req.request != "GET" && req.request != "HEAD") { return (pass); }

if (req.http.Accept-Encoding) {
if (req.http.Accept-Encoding ~ "gzip") {
# If the browser supports it, we'll use gzip.
set req.http.Accept-Encoding = "gzip";
} else if (req.http.Accept-Encoding ~ "deflate") {
# Next, try deflate if it is supported.
set req.http.Accept-Encoding = "deflate";
} else {
# Unknown algorithm. Remove it and send unencoded.
unset req.http.Accept-Encoding;
}
}

}

sub vcl_fetch {
if (req.url ~ "\.(png|gif|jpg|swf|ico)$") { unset beresp.http.set-cookie; }
return (deliver);
}




varnishlog
Quote:
12 SessionOpen c 123.123.123.123 49112 :80
12 ReqStart c 123.123.123.123 49112 435546659
12 RxRequest c GET
12 RxURL c /images/pg/navarrow.png
12 RxProtocol c HTTP/1.1
12 RxHeader c Host: www.mydoomain.com
12 RxHeader c User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:12.0) Gecko/20100101 Firefox/12.0
12 RxHeader c Accept: image/png,image/*;q=0.8,*/*;q=0.5
12 RxHeader c Accept-Language: en-us,en;q=0.5
12 RxHeader c Accept-Encoding: gzip, deflate
12 RxHeader c Referer: http://www.mydomain.com/test-news/2012/2/2816/consultat
12 RxHeader c Cookie: PHPSESSID=9egh9b16fi67gectqfr7q33e12; MY_VISITOR=13359768181082112860XZsFr78ZpVDv; __utma=15553485570.76261333846.133597633822.1335937336822.1335976822.1; __utmb=1555853570.42.31335976822; __utmc=3; __utmz=15558335570.133597683322.1.1.utmgclid=CKDU3
12 RxHeader c X-Forwarded-For: 33.33.33.33
12 RxHeader c Connection: close
12 VCL_call c recv lookup
12 VCL_call c hash
12 Hash c /images/pg/navarrow.png
12 Hash c www.mydomain.com
12 VCL_return c hash
12 VCL_call c miss fetch
12 Backend c 18 default default
12 TTL c 435546659 RFC 0 -1 -1 1335977986 0 1335977986 1334260800 0
12 VCL_call c fetch deliver
12 ObjProtocol c HTTP/1.1
12 ObjResponse c OK
12 ObjHeader c Date: Wed, 02 May 2012 16:59:46 GMT
12 ObjHeader c Server: Apache
12 ObjHeader c Cache-Control: public
12 ObjHeader c Expires: Thu, 12 Apr 2012 20:00:00 GMT
12 ObjHeader c Content-Type: image/png
12 VCL_call c deliver deliver
12 TxProtocol c HTTP/1.1
12 TxStatus c 200
12 TxResponse c OK
12 TxHeader c Server: Apache
12 TxHeader c Cache-Control: public
12 TxHeader c Expires: Thu, 12 Apr 2012 20:00:00 GMT
12 TxHeader c Content-Type: image/png
12 TxHeader c Content-Length: 241
12 TxHeader c Accept-Ranges: bytes
12 TxHeader c Date: Wed, 02 May 2012 16:59:46 GMT
12 TxHeader c X-Varnish: 435546659
12 TxHeader c Age: 0
12 TxHeader c Via: 1.1 varnish
12 TxHeader c Connection: close
12 Length c 241
12 ReqEnd c 435546659 1335977986.090435982 1335977986.092200041 0.000084877 0.001724958 0.000039101

Quote:
15 RxRequest c GET
15 RxURL c /images/thumb/8/d/3/b/8d3b6c2115635_1_V90.jpg
15 VCL_call c recv lookup
15 VCL_call c hash hash
15 VCL_call c miss fetch
15 VCL_call c fetch deliver
15 VCL_call c deliver deliver

Last edited by diabloo; 05-02-2012 at 12:14 PM.
 
Old 08-22-2012, 05:55 PM   #2
TheMadIndian
Member
 
Registered: Dec 2007
Distribution: Fedora Slackware CentOS slax RHEL
Posts: 117

Rep: Reputation: 23
Quote:
Originally Posted by diabloo View Post
I have been attempting to cache only images with varnish. However, I seem to get misses based on what I see from varnishlog. Is there anything wrong with my varnish configuration?




I see miss fetch all the time for my images.


/etc/varnish/default.vcl






varnishlog
Since this is old not sure if it's still relevant but

in vcl_recv add this (limit extensions as you see fit)
Code:
if (req.url ~ "\.(xml|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|htm|html)$") {
                        unset req.http.Cookie;
                        return (lookup);
}
and in vcl_fetch add this (make sure to match the extensions from recv)
Code:
if (req.url ~ "\.(xml|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|htm|html)$") {
                        unset beresp.http.set-cookie;
                }
note the "$" that signifies end of line so if there are querystrings this will not match
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable caching for certain URLs in varnish? How to? linuxlover.chaitanya Linux - Server 3 04-18-2013 07:34 AM
Need information varnish cahing software, memcached db cache chandu.bezawada Linux - Software 1 10-08-2010 07:56 AM
varnish doesn't seams to work on my server Stephan_Craft Linux - Server 1 05-01-2010 03:37 AM
Can't seem to remove Varnish jacatone Linux - Software 3 03-30-2008 04:36 PM
Get Glossy with Varnish jeremy LQ Articles Discussion 0 03-14-2008 11:18 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 07:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration