Check against req.http.Host

In vcl_recv:

     if(req.http.Host ~ "8.8.8.8") {
         error 750;
     }

-Travis Crowder

On Jul 27, 2013, at 3:48 PM, Puneet <[email protected]> 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?://[^/$]+", 
> "http://mywebsite.com";);
>     set obj.http.Location = req.http.X-REDIRURL;
>     set obj.status = 301;
>     unset req.http.X-REDIRURL;
>     return(deliver);
> }
> 
> But this does not redirect the user to the website, instead it delivers the 
> page.
> Can anyone tell what I am missing?
>  
> Thanks
> Puneet
> _______________________________________________
> varnish-misc mailing list
> [email protected]
> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc

_______________________________________________
varnish-misc mailing list
[email protected]
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc

Reply via email to