What's the best way to run Drupal and Django sites behind the same Varnish server?
- by Alexis Bellido
I have a high traffic website running with Drupal and Apache, five web servers behind a Varnish server load balancing. Let's say this site is example.com. I'm using five backends and a director like this in my default.vcl:
director balancer round-robin {
{
.backend = web1;
}
{
.backend = web2;
}
{
.backend = web3;
}
{
.backend = web4;
}
{
.backend = web5;
}
}
Now I'm working on a new Django project that will be a new section of this site running on example.com/new-section.
After checking the documentation I found I can do something like this:
sub vcl_recv {
if (req.url ~ "^/new-section/") {
set req.backend = newbackend;
} else {
set req.backend = default;
}
}
That is, using a different backend for a subdirectory /new-section under the same domain.
My question is, how do I make something like this work with my director and load balancing setup?
I'm probably going to run two or more web servers (backends) with my new Django project, each one with a mix of Gunicorn, Nginx, and a few Python packages, and would like to put all of those in their own Varnish director to load balance.
Is it possible to do use the above approach to decide which director to use?, like this:
sub vcl_recv {
if (req.url ~ "^/new-section/") {
set req.director = newdirector;
} else {
set req.director = balancer;
}
}
All suggestions welcome.
Thanks!