whatismyip – Varnish way

Varnish is very powerful tool and many things can be accomplished by it. One simple example is WhatIsMyIP server (HTTP server that shows you your public IP) served only by varnish (no backend).

In your main vcl (by default is default.vcl) configuration file you need to add couple of lines to accomplish this:

In sub vcl_recv routine, near to top, add:

if (req.http.host ~ “whatismyip”) {
error 408;
}

Then just in sub vcl_error routine add:

if (obj.status == 408) {
set obj.status = 200;
set obj.response = “OK”;
synthetic client.ip;
return(deliver);

}

Then /etc/init.d/varnish reload and voila you get yourself whatismyip server.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: