Issues with Varnish 3.0 + Multiple Wordpress sites

Fabio Fraga [DS] fabio at dataspace.com.br
Tue Apr 4 16:23:19 CEST 2017


Hi, Miguel!

Thanks for sharing the solution.
Im not working with varnish a long time. So, i forgot this simple trick to
solve the problem.

The setup are varnish + nginx + fpm.

Thanks!


Fabio Fraga Machado
phone: (48) 4052-8300 <http://up2it.com.br/assinatura/tel//4840528300>
web: www.dataspace.com.br
email: fabio at dataspace.com.br
skype: boinkbr
  <https://facebook.com/dataspace.brasil> <https://twitter.com/data_space>

On Mon, Apr 3, 2017 at 3:47 PM, Miguel González <miguel_3_gonzalez at yahoo.es>
wrote:

> Not sure about Varnish 3.0 syntax but you need to return a pass in
> vcl_recv for wp-admin and other woocommerce sections (if you have
> woocommerce):
>
>         # --- WordPress specific configuration
>         # Did not cache the admin and login pages
>         if (req.url ~
> "nocache|cart|my-account|checkout|addons|tienda|mi-
> cuenta|carro|producto/*|login|wp-admin|wp-(comments-post|
> login|signup|activate|mail|cron)\.php|preview\=true|
> admin-ajax\.php|xmlrpc\.php|bb-admin|whm-server-status|
> server-status|control\.php|bb-login\.php|bb-reset-password\.
> php|register\.php")
> {
>             return (pass);
>         }
>
>
> Not sure I have understood, those two extra sites run in the same Apache
> server? Why don´t you use virtualhosts instead of port virtualhosts? I
> run Varnish in front of 40 sites run by Apache without needing to
> specify different backends (just one).
>
> Regards,
>
> Miguel
>
>
>
> On 04/03/17 3:51 AM, Fabio Fraga [DS] wrote:
> > Hey, folks.
> >
> > 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.
> >
> > 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.
> >
> > 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.
> > My issue is on wp-admin. I can post text content, but i cant post images
> > (got http error on wordpress).
> > But if i remove the configuration of new backends, all things works fine.
> >
> > Where am i going wrong?
> >
> > Below my default.vcl.
> >
> > ===============================
> >
> > backend default {
> >
> >         .host = “w.x.y.z”;
> >
> >         .port = "8081";
> >
> >         .connect_timeout = 60s;
> >
> >         .first_byte_timeout = 60s;
> >
> >         .between_bytes_timeout = 60s;
> >
> >      }
> >
> > backend bk1 {
> >
> >         .host = “xyz.com.br <http://xyz.com.br>";
> >
> >         .port = "8081";
> >
> >         .connect_timeout = 60s;
> >
> >         .first_byte_timeout = 60s;
> >
> >         .between_bytes_timeout = 60s;
> >
> >      }
> >
> > backend bk2 {
> >
> >         .host = “abc.com.br <http://abc.com.br>";
> >
> >         .port = "8084";
> >
> >         .connect_timeout = 60s;
> >
> >         .first_byte_timeout = 60s;
> >
> >         .between_bytes_timeout = 60s;
> >
> >      }
> >
> > backend bk3 {
> >
> >         .host = “def.com.br <http://def.com.br>";
> >
> >         .port = "8083";
> >
> >         .connect_timeout = 60s;
> >
> >         .first_byte_timeout = 60s;
> >
> >         .between_bytes_timeout = 60s;
> >
> >      }
> >
> > acl purge {
> >
> >   "localhost";
> >
> >   "127.0.0.1";
> >
> >   "w.x.y.z";
> >
> > }
> >
> >
> > sub vcl_recv {
> >
> >
> >   if (req.http.host ~ "^(www\.)?xyz\.com\.br$") {
> >
> >         set req.backend = bk1;
> >
> >         return (lookup);
> >
> >    }
> >
> >   if (req.http.host ~ "^(www\.)?abc\.com\.br$") {
> >
> >         set req.backend = bk2;
> >
> >         return (lookup);
> >
> >    }
> >
> >   if (req.http.host ~ "^(www\.)?def\.com\.br$") {
> >
> >         set req.backend = bk3;
> >
> >         return (lookup);
> >
> >    }
> >
> >
> >   if (req.restarts == 0) {
> >
> >     if (req.http.x-forwarded-for) {
> >
> >       set req.http.X-Forwarded-For =
> >
> >       req.http.X-Forwarded-For + ", " + client.ip;
> >
> >     } else {
> >
> >       set req.http.X-Forwarded-For = client.ip;
> >
> >     }
> >
> >   }
> >
> >
> >   if (req.http.Accept-Encoding) {
> >
> >     if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") {
> >
> >       # No point in compressing these
> >
> >       remove req.http.Accept-Encoding;
> >
> >     } elsif (req.http.Accept-Encoding ~ "gzip") {
> >
> >       set req.http.Accept-Encoding = "gzip";
> >
> >     } elsif (req.http.Accept-Encoding ~ "deflate") {
> >
> >       set req.http.Accept-Encoding = "deflate";
> >
> >     } else {
> >
> >       # unknown algorithm
> >
> >       remove req.http.Accept-Encoding;
> >
> >     }
> >
> >   }
> >
> >
> >   if (req.request == "PURGE") {
> >
> >     if ( !client.ip ~ purge ) {
> >
> >       error 405 "Not allowed.";
> >
> >     }
> >
> >     return (lookup);
> >
> >   }
> >
> >
> >   if (req.request != "GET" &&
> >
> >     req.request != "HEAD" &&
> >
> >     req.request != "PUT" &&
> >
> >     req.request != "POST" &&
> >
> >     req.request != "TRACE" &&
> >
> >     req.request != "OPTIONS" &&
> >
> >     req.request != "DELETE") {
> >
> >       return (pipe);
> >
> >   }
> >
> >
> >   if (req.request != "GET" && req.request != "HEAD") {
> >
> >     return (pass);
> >
> >   }
> >
> >
> >   if ( req.http.cookie ~ "wordpress_logged_in" ) {
> >
> >     return(pass);
> >
> >   }
> >
> >
> >   if (
> >
> >     !(req.url ~ "wp-(login|admin)")
> >
> >     && !(req.url ~ "&preview=true" )
> >
> >   ){
> >
> >     unset req.http.cookie;
> >
> >   }
> >
> >
> >   if (req.http.Authorization || req.http.Cookie) {
> >
> >     return (pass);
> >
> >   }
> >
> >
> >   if (
> >
> >     req.url ~ "preview"
> >
> >     || req.url ~ "nocache"
> >
> >     || req.url ~ "\.css$"
> >
> >     || req.url ~ "\.js$"
> >
> >     || req.url ~ "\.jpg$"
> >
> >     || req.url ~ "\.jpeg$"
> >
> >     || req.url ~ "\.gif$"
> >
> >     || req.url ~ "\.png$"
> >
> >   ) {
> >
> >     return (pass);
> >
> >   }
> >
> >
> >   return (lookup);
> >
> > }
> >
> >
> > sub vcl_hit {
> >
> >
> >   if (req.request == "PURGE") {
> >
> >     purge;
> >
> >     error 200 "Purged.";
> >
> >   }
> >
> >   return (deliver);
> >
> > }
> >
> >
> > sub vcl_miss {
> >
> >   if (req.request == "PURGE") {
> >
> >     purge;
> >
> >     error 200 "Purged.";
> >
> >   }
> >
> >   return (fetch);
> >
> > }
> >
> >
> > sub vcl_fetch {
> >
> >   set beresp.http.Vary = "Accept-Encoding";
> >
> >
> >   if (!(req.url ~ "wp-(login|admin)") && !req.http.cookie ~
> > "wordpress_logged_in" ) {
> >
> >     unset beresp.http.set-cookie;
> >
> >     set beresp.ttl = 5m;
> >
> >   }
> >
> >
> >   if (beresp.ttl <= 0s ||
> >
> >     beresp.http.Set-Cookie ||
> >
> >     beresp.http.Vary == "*") {
> >
> >       set beresp.ttl = 120 s;
> >
> >       return (hit_for_pass);
> >
> >   }
> >
> >
> >   return (deliver);
> >
> >
> > }
> >
> >
> > sub vcl_hash {
> >
> >
> > if (req.http.host) {
> >
> >  hash_data(req.http.host);
> >
> > } else {
> >
> >  hash_data(server.ip);
> >
> > }
> >
> > }
> >
> >
> > sub vcl_deliver {
> >
> >   if (obj.hits > 0) {
> >
> >     set resp.http.X-Cache = "HIT";
> >
> >   } else {
> >
> >     set resp.http.X-Cache = "MISS";
> >
> >   }
> >
> > }
> >
> > =======================
> >
> > Thanks for help,
> >
> >
> >       Fabio Fraga Machado
> > phone: (48) 4052-8300 <http://up2it.com.br/assinatura/tel//4840528300>
> > web: www.dataspace.com.br <http://www.dataspace.com.br/>
> > email: fabio at dataspace.com.br <mailto:fabio at dataspace.com.br>
> > skype: boinkbr
> >   <https://facebook.com/dataspace.brasil><https://twitter.com/data_space
> >
> >
> >
> >
> > _______________________________________________
> > varnish-misc mailing list
> > varnish-misc at varnish-cache.org
> > https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20170404/747ecde2/attachment.html>


More information about the varnish-misc mailing list