<div dir="ltr"><div>Hey, folks.</div><div><br></div><div>I have a setup on CentOS 6.8 server with 1 single ip address and including Varnish + Nginx + php-fpm. Php works on 7.0 version.</div><div><br></div><div>My customer had a single website and the setup works fine so far. But he ask to include a two new websites. My headache starts here.</div><div><br></div><div>When i set the backends pointing to hostname and port (in nginx), varnish redirects to the first site. But, when i set the sub vcl_recv correctly (using regexp), i get the correct websites.</div><div>My issue is on wp-admin. I can post text content, but i cant post images (got http error on wordpress).</div><div>But if i remove the configuration of new backends, all things works fine.</div><div><br></div><div>Where am i going wrong?</div><div><br></div><div>Below my default.vcl.</div><div><br></div><div>===============================</div><div><br></div><div>
<p class="gmail-p1">backend default {</p>
<p class="gmail-p1"> .host = “w.x.y.z”;</p>
<p class="gmail-p1"> .port = "8081";</p>
<p class="gmail-p1"> .connect_timeout = 60s;</p>
<p class="gmail-p1"> .first_byte_timeout = 60s;</p>
<p class="gmail-p1"> .between_bytes_timeout = 60s;</p>
<p class="gmail-p1"> }</p>
<p class="gmail-p1">backend bk1 {</p>
<p class="gmail-p1"> .host = “<a href="http://xyz.com.br">xyz.com.br</a>";</p>
<p class="gmail-p1"> .port = "8081";</p>
<p class="gmail-p1"> .connect_timeout = 60s;</p>
<p class="gmail-p1"> .first_byte_timeout = 60s;</p>
<p class="gmail-p1"> .between_bytes_timeout = 60s;</p>
<p class="gmail-p1"> }</p>
<p class="gmail-p1">backend bk2 {</p>
<p class="gmail-p1"> .host = “<a href="http://abc.com.br">abc.com.br</a>";</p>
<p class="gmail-p1"> .port = "8084";</p>
<p class="gmail-p1"> .connect_timeout = 60s;</p>
<p class="gmail-p1"> .first_byte_timeout = 60s;</p>
<p class="gmail-p1"> .between_bytes_timeout = 60s;</p>
<p class="gmail-p1"> }</p>
<p class="gmail-p1">backend bk3 {</p>
<p class="gmail-p1"> .host = “<a href="http://def.com.br">def.com.br</a>";</p>
<p class="gmail-p1"> .port = "8083";</p>
<p class="gmail-p1"> .connect_timeout = 60s;</p>
<p class="gmail-p1"> .first_byte_timeout = 60s;</p>
<p class="gmail-p1"> .between_bytes_timeout = 60s;</p>
<p class="gmail-p1"> }</p>
<p class="gmail-p1">acl purge {</p>
<p class="gmail-p1"> "localhost";</p>
<p class="gmail-p1"> "127.0.0.1";</p>
<p class="gmail-p1"> "w.x.y.z";</p>
<p class="gmail-p1">}</p>
<p class="gmail-p2"><br></p>
<p class="gmail-p1">sub vcl_recv {</p>
<p class="gmail-p2"><br></p>
<p class="gmail-p1"> if (req.http.host ~ "^(www\.)?xyz\.com\.br$") {</p>
<p class="gmail-p1"> set req.backend = bk1;</p>
<p class="gmail-p1"> return (lookup);</p>
<p class="gmail-p1"> }</p>
<p class="gmail-p1"> if (req.http.host ~ "^(www\.)?abc\.com\.br$") {</p>
<p class="gmail-p1"> set req.backend = bk2;</p>
<p class="gmail-p1"> return (lookup);</p>
<p class="gmail-p1"> }</p>
<p class="gmail-p1"> if (req.http.host ~ "^(www\.)?def\.com\.br$") {</p>
<p class="gmail-p1"> set req.backend = bk3;</p>
<p class="gmail-p1"> return (lookup);</p>
<p class="gmail-p1"> }</p>
<p class="gmail-p2"><br></p>
<p class="gmail-p1"> if (req.restarts == 0) {</p>
<p class="gmail-p1"> if (req.http.x-forwarded-for) {</p>
<p class="gmail-p1"> set req.http.X-Forwarded-For =</p>
<p class="gmail-p1"> req.http.X-Forwarded-For + ", " + client.ip;</p>
<p class="gmail-p1"> } else {</p>
<p class="gmail-p1"> set req.http.X-Forwarded-For = client.ip;</p>
<p class="gmail-p1"> }</p>
<p class="gmail-p1"> }</p>
<p class="gmail-p2"><br></p>
<p class="gmail-p1"> if (req.http.Accept-Encoding) {</p>
<p class="gmail-p1"> if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") {</p>
<p class="gmail-p1"> # No point in compressing these</p>
<p class="gmail-p1"> remove req.http.Accept-Encoding;</p>
<p class="gmail-p1"> } elsif (req.http.Accept-Encoding ~ "gzip") {</p>
<p class="gmail-p1"> set req.http.Accept-Encoding = "gzip";</p>
<p class="gmail-p1"> } elsif (req.http.Accept-Encoding ~ "deflate") {</p>
<p class="gmail-p1"> set req.http.Accept-Encoding = "deflate";</p>
<p class="gmail-p1"> } else {</p>
<p class="gmail-p1"> # unknown algorithm</p>
<p class="gmail-p1"> remove req.http.Accept-Encoding;</p>
<p class="gmail-p1"> }</p>
<p class="gmail-p1"> }</p>
<p class="gmail-p2"><br></p>
<p class="gmail-p1"> if (req.request == "PURGE") {</p>
<p class="gmail-p1"> if ( !client.ip ~ purge ) {</p>
<p class="gmail-p1"> error 405 "Not allowed.";</p>
<p class="gmail-p1"> }</p>
<p class="gmail-p1"> return (lookup);</p>
<p class="gmail-p1"> }</p>
<p class="gmail-p2"><br></p>
<p class="gmail-p1"> if (req.request != "GET" &&</p>
<p class="gmail-p1"> req.request != "HEAD" &&</p>
<p class="gmail-p1"> req.request != "PUT" &&</p>
<p class="gmail-p1"> req.request != "POST" &&</p>
<p class="gmail-p1"> req.request != "TRACE" &&</p>
<p class="gmail-p1"> req.request != "OPTIONS" &&</p>
<p class="gmail-p1"> req.request != "DELETE") {</p>
<p class="gmail-p1"> return (pipe);</p>
<p class="gmail-p1"> }</p>
<p class="gmail-p2"><br></p>
<p class="gmail-p1"> if (req.request != "GET" && req.request != "HEAD") {</p>
<p class="gmail-p1"> return (pass);</p>
<p class="gmail-p1"> }</p>
<p class="gmail-p2"><br></p>
<p class="gmail-p1"> if ( req.http.cookie ~ "wordpress_logged_in" ) {</p>
<p class="gmail-p1"> return(pass);</p>
<p class="gmail-p1"> }</p>
<p class="gmail-p2"><br></p>
<p class="gmail-p1"> if (</p>
<p class="gmail-p1"> !(req.url ~ "wp-(login|admin)")</p>
<p class="gmail-p1"> && !(req.url ~ "&preview=true" )</p>
<p class="gmail-p1"> ){</p>
<p class="gmail-p1"> unset req.http.cookie;</p>
<p class="gmail-p1"> }</p>
<p class="gmail-p2"><br></p>
<p class="gmail-p1"> if (req.http.Authorization || req.http.Cookie) {</p>
<p class="gmail-p1"> return (pass);</p>
<p class="gmail-p1"> }</p>
<p class="gmail-p2"><br></p>
<p class="gmail-p1"> if (</p>
<p class="gmail-p1"> req.url ~ "preview"</p>
<p class="gmail-p1"> || req.url ~ "nocache"</p>
<p class="gmail-p1"> || req.url ~ "\.css$"</p>
<p class="gmail-p1"> || req.url ~ "\.js$"</p>
<p class="gmail-p1"> || req.url ~ "\.jpg$"</p>
<p class="gmail-p1"> || req.url ~ "\.jpeg$"</p>
<p class="gmail-p1"> || req.url ~ "\.gif$"</p>
<p class="gmail-p1"> || req.url ~ "\.png$"</p>
<p class="gmail-p1"> ) {</p>
<p class="gmail-p1"> return (pass);</p>
<p class="gmail-p1"> }</p>
<p class="gmail-p2"><br></p>
<p class="gmail-p1"> return (lookup);</p>
<p class="gmail-p1">}</p>
<p class="gmail-p2"><br></p>
<p class="gmail-p1">sub vcl_hit {</p>
<p class="gmail-p2"><br></p>
<p class="gmail-p1"> if (req.request == "PURGE") {</p>
<p class="gmail-p1"> purge;</p>
<p class="gmail-p1"> error 200 "Purged.";</p>
<p class="gmail-p1"> }</p>
<p class="gmail-p1"> return (deliver);</p>
<p class="gmail-p1">}</p>
<p class="gmail-p2"><br></p>
<p class="gmail-p1">sub vcl_miss {</p>
<p class="gmail-p1"> if (req.request == "PURGE") {</p>
<p class="gmail-p1"> purge;</p>
<p class="gmail-p1"> error 200 "Purged.";</p>
<p class="gmail-p1"> }</p>
<p class="gmail-p1"> return (fetch);</p>
<p class="gmail-p1">}</p>
<p class="gmail-p2"><br></p>
<p class="gmail-p1">sub vcl_fetch {</p>
<p class="gmail-p1"> set beresp.http.Vary = "Accept-Encoding";</p>
<p class="gmail-p2"><br></p>
<p class="gmail-p1"> if (!(req.url ~ "wp-(login|admin)") && !req.http.cookie ~ "wordpress_logged_in" ) {</p>
<p class="gmail-p1"> unset beresp.http.set-cookie;</p>
<p class="gmail-p1"> set beresp.ttl = 5m;</p>
<p class="gmail-p1"> }</p>
<p class="gmail-p2"><br></p>
<p class="gmail-p1"> if (beresp.ttl <= 0s ||</p>
<p class="gmail-p1"> beresp.http.Set-Cookie ||</p>
<p class="gmail-p1"> beresp.http.Vary == "*") {</p>
<p class="gmail-p1"> set beresp.ttl = 120 s;</p>
<p class="gmail-p1"> return (hit_for_pass);</p>
<p class="gmail-p1"> }</p>
<p class="gmail-p2"><br></p>
<p class="gmail-p1"> return (deliver);</p>
<p class="gmail-p2"><br></p>
<p class="gmail-p1">}</p>
<p class="gmail-p2"><br></p>
<p class="gmail-p1">sub vcl_hash {</p>
<p class="gmail-p2"><br></p>
<p class="gmail-p1">if (req.http.host) {</p>
<p class="gmail-p1"> hash_data(req.http.host);</p>
<p class="gmail-p1">} else {</p>
<p class="gmail-p1"> hash_data(server.ip);</p>
<p class="gmail-p1"><span class="gmail-Apple-tab-span"> </span>}</p>
<p class="gmail-p1">}</p>
<p class="gmail-p2"><br></p>
<p class="gmail-p1">sub vcl_deliver {</p>
<p class="gmail-p1"> if (obj.hits > 0) {</p>
<p class="gmail-p1"> set resp.http.X-Cache = "HIT";</p>
<p class="gmail-p1"> } else {</p>
<p class="gmail-p1"> set resp.http.X-Cache = "MISS";</p>
<p class="gmail-p1"> }</p>
<p class="gmail-p1">}</p><p class="gmail-p1">=======================</p></div><div>Thanks for help,</div><div><br></div><div><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><table style="border-collapse:collapse;font-family:georgia,"times new roman",times,serif"><tbody><tr><td style="padding:0px 16px 0px 0px;vertical-align:top"><img src="http://up2it.com.br/assinatura/images/ds.png" style="border: 0px; vertical-align: middle;"></td><td style="padding:0px 0px 0px 8px;vertical-align:top;border-left:3px solid rgb(30,144,255);border-top-color:rgb(30,144,255);border-right-color:rgb(30,144,255);border-bottom-color:rgb(30,144,255)"><span><span style="font-size:13px;font-family:arial;font-weight:bold">Fabio Fraga Machado</span></span><div style="padding:2px 0px 0px"><div><span style="color:rgb(30,144,255);font-size:11px;font-family:arial;font-weight:bold">phone:</span> <span style="font-size:11px;font-family:arial"><a href="http://up2it.com.br/assinatura/tel//4840528300" style="color:rgb(0,0,0);text-decoration:none;background-color:transparent" target="_blank">(48) 4052-8300</a></span></div><div><span style="color:rgb(30,144,255);font-size:11px;font-family:arial;font-weight:bold">web:</span> <span style="font-size:11px;font-family:arial"><a href="http://www.dataspace.com.br/" style="color:rgb(0,0,0);text-decoration:none;background-color:transparent" target="_blank">www.dataspace.com.br</a></span></div><div><span style="color:rgb(30,144,255);font-size:11px;font-family:arial;font-weight:bold">email:</span> <span style="font-size:11px;font-family:arial"><a href="mailto:fabio@dataspace.com.br" style="color:rgb(0,0,0);text-decoration:none;background-color:transparent" target="_blank">fabio@dataspace.com.br</a></span></div><div><span style="color:rgb(30,144,255);font-size:11px;font-family:arial;font-weight:bold">skype:</span> <span style="font-size:11px;font-family:arial"><a style="color:rgb(0,0,0);text-decoration:none;background-color:transparent">boinkbr</a></span></div></div><div style="padding:3px 0px 0px"><a href="https://facebook.com/dataspace.brasil" style="color:rgb(69,130,236);text-decoration:none;background-color:transparent" target="_blank"><img src="http://up2it.com.br/assinatura/images/f.png" style="border: 0px; vertical-align: middle; width: 18px; height: 18px; margin: 2px;"> </a><a href="https://twitter.com/data_space" style="color:rgb(69,130,236);text-decoration:none;background-color:transparent" target="_blank"><img src="http://up2it.com.br/assinatura/images/t.png" style="border: 0px; vertical-align: middle; width: 18px; height: 18px; margin: 2px;"></a></div></td></tr></tbody></table><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"></div></div></div></div></div></div></div></div></div></div></div>
</div></div>