Stop users accessing website via IP address

Puneet puneet.arora at
Sun Jul 28 04:38:24 CEST 2013

HI Travis,


Thanks for the reply.

I think that should work.


Just one question.

In sub vcl_error() should I also change the 


set req.http.X-REDIRURL = regsub(req.url,"https?://[^/$]+", "

TO : -->

set req.http.X-REDIRURL = regsub(,"https?://[^/$]+", "



Because when replace req.url with, It again stops working.

And If I don't do it, the bowser gives an error "Too many redirects"





From: Travis Crowder [mailto:travis.crowder at] 
Sent: Saturday, July 27, 2013 7:53 PM
To: Puneet
Cc: varnish-misc at
Subject: Re: Stop users accessing website via IP address


Check against req.http.Host


In vcl_recv:


     if(req.http.Host ~ "") {

         error 750;



-Travis Crowder


On Jul 27, 2013, at 3:48 PM, Puneet <puneet.arora at
<mailto:puneet.arora at> > wrote:

Hi all,

I want to stop the users accessing my website via IP address.
I am using varnish as cache.
I have the following code in place but it is not working.

In vcl_recv() {
     if(req.url ~ "XX.XX.XXX.XXX") {
     error 750 "Moved Permanently";
  } } 

And in vcl_error()
sub vcl_error {
    if (obj.status == 750) {
    set req.http.X-REDIRURL = regsub(req.url,"https?://[^/$]+", "
    set obj.http.Location = req.http.X-REDIRURL;
    set obj.status = 301;
    unset req.http.X-REDIRURL;

But this does not redirect the user to the website, instead it delivers the
Can anyone tell what I am missing?




varnish-misc mailing list
 <mailto:varnish-misc at> varnish-misc at


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the varnish-misc mailing list