<div dir="ltr">Hello, Puneet. You'll need to do the blocking on the sub vcl_recv and not sub vcl_error.<div><br></div><div>Here's an easy VCL config example:<div><br></div><font face="courier new, monospace">acl forbidden {<br>

  "xxx.xxx.xxx.xxx";<br>  "xxx.xxx.xxx.xxx";<br>}<br><br>sub vcl_recv {<br>  # Prevent access from these hosts<br>  if (client.ip ~ forbidden) {<br>    error 403 "Forbidden";<br>  }<br>}</font></div>

<div class="gmail_extra"><br>Let me know if you have any other questions.</div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jul 27, 2013 at 1:48 PM, Puneet <span dir="ltr"><<a href="mailto:puneet.arora@insticator.com" target="_blank">puneet.arora@insticator.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="#0563C1" vlink="#954F72"><div><p class="MsoNormal"><span style="background:white;font-size:10.0pt;font-family:"Arial","sans-serif"">Hi all,<u></u><u></u></span></p>

<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif""><br><span style="background:white">I want to stop the users accessing my website via IP address.</span><br><span style="background:white">I am using varnish as cache.</span><br>

<span style="background:white">I have the following code in place but it is not working.</span><br><br><span style="background:white">In vcl_recv() {</span><br><span style="background:white">     if(req.url ~ "XX.XX.XXX.XXX") {</span><br>

<span style="background:white">     error 750 "Moved Permanently";</span><br><span style="background:white">  } }<span> </span></span><br><br><span style="background:white">And in vcl_error()</span><br><span style="background:white">sub vcl_error {</span><br>

<span style="background:white">    if (obj.status == 750) {</span><br><span style="background:white">    set req.http.X-REDIRURL = regsub(req.url,"https?://[^/$]+", "</span></span><a href="http://www.linkedin.com/redirect?url=http%3A%2F%2Fmywebsite%2Ecom&urlhash=5qRF&_t=tracking_anet" target="_blank"><span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:#006699;border:none windowtext 1.0pt;padding:0in;background:white;text-decoration:none">http://mywebsite.com</span></a><span style="background:white;font-size:10.0pt;font-family:"Arial","sans-serif"">");</span><span style="font-size:10.0pt;font-family:"Arial","sans-serif""><br>

<span style="background:white">    set obj.http.Location = req.http.X-REDIRURL;</span><br><span style="background:white">    set obj.status = 301;</span><br><span style="background:white">    unset req.http.X-REDIRURL;</span><br>

<span style="background:white">    return(deliver);</span><br><span style="background:white">}</span><br><br><span style="background:white">But this does not redirect the user to the website, instead it delivers the page.</span><br>

<span style="background:white">Can anyone tell what I am missing?<u></u><u></u></span></span></p><p class="MsoNormal"><span style="background:white;font-size:10.0pt;font-family:"Arial","sans-serif""><u></u> <u></u></span></p>

<p class="MsoNormal"><span style="background:white;font-size:10.0pt;font-family:"Arial","sans-serif"">Thanks<span class="HOEnZb"><font color="#888888"><u></u><u></u></font></span></span></p><span class="HOEnZb"><font color="#888888"><p class="MsoNormal">

<span style="background:white;font-size:10.0pt;font-family:"Arial","sans-serif"">Puneet</span><u></u><u></u></p></font></span></div></div><br>_______________________________________________<br>
varnish-misc mailing list<br>
<a href="mailto:varnish-misc@varnish-cache.org">varnish-misc@varnish-cache.org</a><br>
<a href="https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc" target="_blank">https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br>

<div dir="ltr">Stephen Wood<div>Dev/Ops Engineer</div><div>Moz, Inc.</div><div>Website: <a href="http://www.heystephenwood.com" target="_blank">www.heystephenwood.com</a></div></div>
</div></div>