Website migration using Varnish?

Hugo Cisneiros (Eitch) hugo.cisneiros at gmail.com
Mon Aug 12 16:39:56 CEST 2013


On Mon, Aug 12, 2013 at 6:49 AM,  <superoverdrive at gmx.de> wrote:
> I would like to migrate a very old PHP website to Java - without loosing all
> internal pages...however I also do not want to migrate 100% of the old
> website, only abour 80%.
>
> My plan is to use varnish in order to fetch Tomcat (or Apache->Tomcat) pages
> from the new application and deliver all urls not found on the new
> application from the old php application.

Setup two backends:

backend be_java {
   [...]
}

backend be_php {
   [...]
}

On vcl_recv, the default backend will be the java one, meaning all
requests will go to the java backend first. But if you receive the
request if a custom header, you will serve from the PHP backend. This
custom header will be appended to the request by varnish when it gets
a 404 object response from the java backend:

sub vcl_recv {
  set req.backend = be_java;

  # if custom header is present, use the php backend
  if (req.http.X-Serve-From-Old == "1") {
    unset req.http.X-Serve-From-Old;
    set req.backend = be_php;
  }

  [...]
}

sub vcl_fetch {
  if (req.backend == be_java && beresp.status == 404) {
    # set custom header and restart request.
    set req.http.X-Serve-From-Old = "1";
    return (restart);
  }

  [...]
}

This should do the trick.

> Would you recommend to use Tomcat without Apache or with Apache?

It really depends if you're using apache features or not :) People use
apache in front of Tomcat to mix static and dynamic items, to use
mod_rewrite features easily, to virtual hosts with different dynamic
languages and so on. But if you're just using the application, keep it
simple.

-- 
[]'s
Hugo
www.devin.com.br



More information about the varnish-misc mailing list