{"id":716,"date":"2013-08-07T09:34:24","date_gmt":"2013-08-07T09:34:24","guid":{"rendered":"http:\/\/invisiblezero.net\/?p=716"},"modified":"2013-08-07T09:34:24","modified_gmt":"2013-08-07T09:34:24","slug":"varnish-cache-server-guru-meditation-503","status":"publish","type":"post","link":"http:\/\/ndthanh.com\/varnish-cache-server-guru-meditation-503\/","title":{"rendered":"Varnish cache server – Guru Meditation 503 …"},"content":{"rendered":"
<\/p>\n
Recently, i face this annoying error with my varnish cache server<\/p>\n
Error 503 Service Unavailable
\nService Unavailable
\nGuru Meditation:
\nXID: 1937610824
\nVarnish cache server<\/p>\n
<\/p>\n
this issue scared me \ud83d\ude41 , because everything has been working well with varnish cache server. luckily, i had this issue at the moment i deployed a new feature that will send a big file over http protocol with content type = ‘application\/octet-stream’.<\/p>\n
from this point, i suspected that varnish cache server has something to do with large file transfer over http. so the question is : how to ignore varnish cache in such case ?<\/p>\n
after googling and studying varnish cache, i found that we can do it with a simple rule. this rule returns pipe – AKA : content from back end server directly to client<\/p>\n
\n# bypass export CSV , you can replace your url pattern with \/exportlimit\/all\/\nif ( req.url ~ ".*\/exportlimit\/all\/.*" ) {\n set req.http.connection = "close";\n return(pipe);\n}\n<\/pre>\nthis is where it should be in varnish VCL file (\/etc\/varnsih\/default.vcl or else where you specified)<\/p>\n
\nsub vcl_recv {\n if (req.restarts == 0) {\n if (req.http.x-forwarded-for) {\n set req.http.X-Forwarded-For =\n req.http.X-Forwarded-For + ", " + client.ip;\n } else {\n set req.http.X-Forwarded-For = client.ip;\n }\n }\n\n if (req.request != "GET" &&\n req.request != "HEAD" &&\n req.request != "PUT" &&\n req.request != "POST" &&\n req.request != "TRACE" &&\n req.request != "OPTIONS" &&\n req.request != "DELETE" &&\n req.request != "PURGE") {\n \/* Non-RFC2616 or CONNECT which is weird. *\/\n return (pipe);\n }\n\n # bypass export CSV\n if ( req.url ~ ".*\/exportlimit\/all\/.*" ) {\n set req.http.connection = "close";\n return(pipe);\n }\n\n # purge request\n if (req.request == "PURGE") {\n if (!client.ip ~ purge) {\n error 405 "Not allowed.";\n }\n ban("obj.http.X-Purge-Host ~ " + req.http.X-Purge-Host + " && obj.http.X-Purge-URL ~ " + req.http.X-Purge-Regex + " && obj.http.Content-Type ~ " + req.http.X-Purge-Content-Type);\n error 200 "Purged.";\n }\n\n # switch to admin backend configuration\n if (req.http.cookie ~ "adminhtml=") {\n set req.backend = admin;\n }\n<\/pre>\nremember to restart\/reload varnish cache server after having it planted in the VCL file<\/p>\n
\nservice varnish restart\n<\/pre>\n","protected":false},"excerpt":{"rendered":"Recently, i face this annoying error with my varnish cache server Error 503 Service Unavailable Service Unavailable Guru Meditation: XID: 1937610824 Varnish cache server this issue scared me \ud83d\ude41 , because everything has been working well with varnish cache server. luckily, i had this issue at the moment i deployed a new feature that will…<\/p>\n