Configure varnish to pipe a subdomain
Erik
duja at torlen.net
Tue Jan 22 10:37:50 CET 2008
Original Message -----------------------
Hello list,
I installed varnish on a staging system today and I am totally impressed
by the performance.
Unfortunately I'm no regex expert, so I will need your help with this
config issue.
I want to use varnish for a domain - lets call it "example.com"
The domain has got a subdomain "admin.example.com" - any GET / POST to
this subdomain and any pages underneath should not be cached but should
directly passed to the backend.
This is my config - which does not work for as the requests to
admin.example.com as they are also being cached :-(
Thanks so much for your help!
Philipp
Neither am I a regex expert, but I dont think that the regex is the problem. You are using http.url instead of using http.host.
And if im not totally wrong, you dont need the ~ to check the host, you can use ==.
Change this:
if (req.http.url ~ "admin.example.com$") {
pipe;
}
To this:
if (req.http.host == "admin.example.com") {
pipe;
}
And this:
if (req.http.Cookie && req.http.url ~ "admin.example.com$") {
pipe;
}
To this:
if (req.http.Cookie && req.http.host == "admin.example.com") {
pipe;
}
Althought I do not know if you should pipe the cookies. I think its pass that would be used when cookies is set but Im not an expert, maybe im wrong.
Cheers
Erik
-------------------------------------------
(comments are in german - please dont bother!):
/* Definition Default Backend */
backend default {
set backend.host = "127.0.0.1";
set backend.port = "1234";
}
sub vcl_recv {
/* Falls etwas an den Server geschickt wird, geben wir das durch */
if (req.request == "POST") {
pipe;
}
/* Anfragen an die "admin" Seite werden direkt durchgereicht /*
if (req.http.url ~ "admin.example.com$") {
pipe;
}
if (req.http.Cookie && req.http.url ~ "admin.example.com$") {
pipe;
}
if (req.http.Expect) {
pipe;
}
/* Wir cachen Bilder, Dokumente, Audio und FLV Filme*/
if (req.url ~
"\.(jpg|jpeg|gif|png|tiff|tif|svg|swf|flv|ico|doc|ppt|xls|pdf|mp3|mp4|mp4a|ogg)$")
{
lookup;
}
/* Wir cachen auch CSS und javascript */
if (req.url ~ "\.(css|js)$") {
lookup;
}
/* Und wir cachen HTML Code */
if (req.url ~ "\.(html|htm)$") {
lookup;
}
/* Filme cachen wir auch - testweise */
if (req.url ~ "\.(mov|avi|wmv)$") {
lookup;
}
/* ZIP Dateien cachen wir experimentell auch */
if (req.url ~ "\.(zip)$") {
lookup;
}
/* Cookie Requests an die Hauptseite cachen wir weg */
if (req.http.Cookie) {
lookup;
}
/* Kein Caching fuer Content hinter http authentification */
if (req.http.Authenticate || req.http.Authorization) {
pipe;
}
/* Oh und wir cachen alles andere */
lookup;
}
sub vcl_fetch {
/* Wir setzen die TTL fuer jedes Objekt das eine TTL von unter
60sec hat auf 60sec */
if (obj.ttl < 60s) {
}
if (!obj.valid) {
error;
}
if (!obj.cacheable) {
pass;
}
if (obj.http.Set-Cookie) {
pass;
}
/* Wir cachen HTML maximal 30 Minuten */
if (req.url ~ "\.(htm|html)$") {
set obj.ttl = 1800s;
}
/* Wir cachen jedes Objekt maximal fuer drei Stunden */
set obj.ttl = 10800s;
}
sub vcl_hit {
if (req.request == "PURGE") {
set obj.ttl = 0s;
error 200 "Purged.";
}
}
sub vcl_miss {
if (req.request == "PURGE") {
error 404 "Not in cache.";
}
}
_______________________________________________
varnish-misc mailing list
varnish-misc at projects.linpro.no
http://projects.linpro.no/mailman/listinfo/varnish-misc
More information about the varnish-misc
mailing list