<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.hoenzb
        {mso-style-name:hoenzb;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Hi Stephen,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I think I did not stated the problem correctly.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Let me explain the issue:<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Say, my website <a href="http://www.mywebsite.com">www.mywebsite.com</a> is hosted on IP : 167.123.98.20<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Now the Users could type in the IP address i.e. 167.123.98.20 and access my website as the server is listening at port 80.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Now, if any user does that, I want to redirect the Users to <a href="http://www.mywebsite.com">www.mywebsite.com</a>.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I don’t want any User transaction to be done using 167.123.98.20.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Therefore I had the following code in place.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>//If the User access my website using the IP address<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New";background:white'>vcl_recv() {</span><span style='font-size:10.0pt;font-family:"Courier New"'><br><span style='background:white'>     if(req.url ~ "</span></span><span style='font-size:11.0pt;font-family:"Courier New";color:#1F497D'>167.123.98.20</span><span style='font-size:10.0pt;font-family:"Courier New";background:white'>") {</span><span style='font-size:10.0pt;font-family:"Courier New"'><br><span style='background:white'>     error 750 "Moved Permanently";</span><br><span style='background:white'>  } } <o:p></o:p></span></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";background:white'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Redirect the user to www.mywebsite.com.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New";background:white'>sub vcl_error {</span><span style='font-size:10.0pt;font-family:"Courier New"'><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><span style='font-family:"Courier New"'><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;color:#006699;border:none windowtext 1.0pt;padding:0in;background:white;text-decoration:none'>http://mywebsite.com</span></a></span><span style='font-size:10.0pt;font-family:"Courier New";background:white'>");</span><span style='font-size:10.0pt;font-family:"Courier New"'><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'>}<o:p></o:p></span></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I hope I clarified the issue.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Thanks<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Puneet<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><b><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'>From:</span></b><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'> Stephen Wood [mailto:smwood4@gmail.com] <br><b>Sent:</b> Saturday, July 27, 2013 5:05 PM<br><b>To:</b> Puneet<br><b>Cc:</b> varnish-misc@varnish-cache.org<br><b>Subject:</b> Re: Stop users accessing website via IP address<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>Hello, Puneet. You'll need to do the blocking on the sub vcl_recv and not sub vcl_error.<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Here's an easy VCL config example:<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><p class=MsoNormal><span style='font-family:"Courier New"'>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>}</span><o:p></o:p></p></div><div><p class=MsoNormal><br>Let me know if you have any other questions.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>On Sat, Jul 27, 2013 at 1:48 PM, Puneet <<a href="mailto:puneet.arora@insticator.com" target="_blank">puneet.arora@insticator.com</a>> wrote:<o:p></o:p></p><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in'><div><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif";background:white'>Hi all,</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><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><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='font-size:10.0pt;font-family:"Arial","sans-serif";background:white'>");</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?</span></span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif";background:white'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif";background:white'>Thanks</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:#888888;background:white'>Puneet</span><span style='color:#888888'><o:p></o:p></span></p></div></div><p class=MsoNormal><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><o:p></o:p></p></blockquote></div><p class=MsoNormal><br><br clear=all><o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><p class=MsoNormal>-- <o:p></o:p></p><div><p class=MsoNormal>Stephen Wood<o:p></o:p></p><div><p class=MsoNormal>Dev/Ops Engineer<o:p></o:p></p></div><div><p class=MsoNormal>Moz, Inc.<o:p></o:p></p></div><div><p class=MsoNormal>Website: <a href="http://www.heystephenwood.com" target="_blank">www.heystephenwood.com</a><o:p></o:p></p></div></div></div></div></div></body></html>