<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt">Dear all,<br><br> I have Varnish as a front-end and an Apache/PHP running a Symfony application as a backend.<br><br> I had mod_pagespeed enabled in Apache long time before I decided to put Varnish in front of it. It worked well.<br><br> Since we decided to put Varnish in front, we are getting many errors logged in error_log file of this kind:<br><br> Fri May 10 08:29:15 2013] [warn] [mod_pagespeed 1.3.25.4-2941 @17719] Fetch
failed for <a href="http://www.awwwards.com/awards/images/2013/05/xfree_fonts_2013_web_oranienbaum.jpg.pagespeed.ic.t1diDHbOw9.jpg">http://www.midomain.com/images//image2.jpg.pagespeed.ic.t1diDHbOw9.jpg</a>,
status=404<div><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"> and others like:</div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"> <br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"> [warn] [mod_pagespeed 1.1.23.2-2258 @28956] Fetch timed out: http://127.0.0.1:8000/media/cache/thumb_image_user6.jpg (35) waiting for 50 ms</div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif;
background-color: transparent; font-style: normal;"> the result is that the webpage is not loading as fast as it did without varnish.</div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"> I have googled around and I found webpages like this one:</div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;">
http://serverfault.com/questions/290776/mod-pagespeed-varnish-and-apache-cache-issues-after-new-code-pushes</div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"> but since I'm quite new to Varnish I don't really know what I should do.</div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"> Regards,</div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif;
background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"> Miguel</div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;">here is my default.vcl</div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;">backend default {<br> .host = "127.0.0.1";<br> .port =
"8000";<br> .connect_timeout = 600s;<br> .first_byte_timeout = 600s;<br> .between_bytes_timeout = 600s;<br>}<br><br>acl purge {<br> "localhost";<br>}<br><br>acl ban {<br> "localhost";<br>}<br><br>sub vcl_recv {<br> // Strip cookies for static files:<br> if (req.url ~ "\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm|xml)$") {<br> unset req.http.Cookie;<br> }<br><br> // Remove specific cookies:<br> set req.http.Cookie = regsuball(req.http.Cookie, "has_js=[^;]+(; )?", "");<br> set req.http.Cookie = regsuball(req.http.Cookie, "__utm.=[^;]+(; )?", "");<br> set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");<br> if (req.http.cookie ~ "^ *$") { unset req.http.cookie; }<br> if (req.http.Cookie ~ "^\s*$") { unset req.http.Cookie; }<br> if (req.http.Cookie == "") { remove req.http.Cookie; }<br><br> //
Normalize Accept-Encoding header (straight from the manual: https://www.varnish-cache.org/docs/3.0/tutorial/vary.html)<br> if (req.http.Accept-Encoding) {<br> if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") {<br> // No point in compressing these<br> remove req.http.Accept-Encoding;<br> } elsif (req.http.Accept-Encoding ~ "gzip") {<br> set req.http.Accept-Encoding = "gzip";<br> } elsif (req.http.Accept-Encoding ~ "deflate") {<br> set req.http.Accept-Encoding = "deflate";<br> } else {<br> // unkown algorithm<br> remove req.http.Accept-Encoding;<br> }<br> }<br><br> if (req.restarts == 0) {<br> if (req.http.x-forwarded-for)
{<br> set req.http.X-Forwarded-For = req.http.X-Forwarded-For;<br> } else {<br> set req.http.X-Forwarded-For = client.ip;<br> }<br> }<br><br> if (req.request != "GET" &&<br> req.request != "HEAD" &&<br> req.request != "PUT" &&<br> req.request != "POST" &&<br> req.request != "TRACE" &&<br> req.request != "OPTIONS" &&<br> req.request != "DELETE") {<br> /* Non-RFC2616 or CONNECT which is weird. */<br> return (pipe);<br> }<br><br> if (req.request != "GET" && req.request != "HEAD") {<br> /* We only deal with GET and HEAD by default */<br> return (pass);<br> }<br><br> if
(req.http.Authorization || req.http.Cookie) {<br> /* Not cacheable by default */<br> return (pass);<br> }<br><br> if (req.request == "PURGE") {<br> if (!client.ip ~ purge) {<br> error 405 "Not allowed.";<br> }<br> return (lookup);<br> }<br><br> if (req.request == "BAN") {<br> if (!client.ip ~ ban) {<br> error 405 "Not allowed.";<br> }<br> ban("req.http.host == " + req.http.host + "&& req.url == " + req.url);<br> error 200 "Ban added";<br> }<br><br> return (lookup);<br>}<br><br>sub vcl_pipe {<br> set bereq.http.connection = "close";<br> return (pipe);<br>}<br><br>sub vcl_pass {<br> return (pass);<br>}<br><br>sub vcl_hash {<br> hash_data(req.url);<br> if
(req.http.host) {<br> hash_data(req.http.host);<br> } else {<br> hash_data(server.ip);<br> }<br><br> // If the client supports compression, keep that in a different cache<br> if (req.http.Accept-Encoding) {<br> hash_data(req.http.Accept-Encoding);<br> }<br><br> return (hash);<br>}<br><br>sub vcl_hit {<br> if (req.request == "PURGE") {<br> purge;<br> error 200 "Purged.";<br> }<br><br> //Listen to browser force refresh<br> if (req.http.Cache-Control ~ "no-cache") {<br> if (! (req.http.Via || req.http.User-Agent ~ "bot|MSIE")) {<br> set obj.ttl = 0s;<br> return (restart);<br> }<br> }<br><br> return (deliver);<br>}<br><br>sub vcl_miss {<br> if (req.request == "PURGE") {<br>
purge;<br> error 200 "Purged.";<br> }<br><br> return (fetch);<br>}<br><br>sub vcl_fetch {<br> if (beresp.ttl <= 0s ||<br> beresp.http.Set-Cookie ||<br> beresp.http.Vary == "*") {<br> set beresp.ttl = 120 s;<br> return (hit_for_pass);<br> }<br> return (deliver);<br>}<br><br>sub vcl_deliver {<br> // Debugging<br> if (obj.hits > 0) {<br> set resp.http.X-Cache = "HIT";<br> } else {<br> set resp.http.X-Cache = "MISS";<br> }<br><br> // Remove some headers: PHP version<br> unset resp.http.X-Powered-By;<br><br> // Remove some headers: Apache version & OS<br> unset resp.http.Server;<br><br> return (deliver);<br>}<br><br>sub vcl_error {<br> set obj.http.Content-Type = "text/html; charset=utf-8";<br> set
obj.http.Retry-After = "5";<br> synthetic {"<br><?xml version="1.0" encoding="utf-8"?><br><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"<br> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><br><html><br> <head><br> <title>"} + obj.status + " " + obj.response + {"</title><br> </head><br> <body><br> <h1>Error "} + obj.status + " " + obj.response + {"</h1><br> <p>"} + obj.response + {"</p><br> <h3>Guru Meditation:</h3><br> <p>XID: "} + req.xid + {"</p><br> <hr><br> <p>Varnish cache server</p><br> </body><br></html><br>"};<br> return (deliver);<br>}<br><br>sub vcl_init {<br> return (ok);<br>}<br><br>sub vcl_fini {<br> return
(ok);<br>}<br><br></div></div></body></html>