<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)"><base href="x-msg://2/"><style><!--
/* Font Definitions */
@font-face
        {font-family:Helvetica;
        panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@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.apple-converted-space
        {mso-style-name:apple-converted-space;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@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 Travis,<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 for the reply.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I think that should work.<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'>Just one question.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>In sub vcl_error() should I also change the <o:p></o:p></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:10.0pt;font-family:"Arial","sans-serif";background:white'>set req.http.X-REDIRURL = regsub(<b>req.url</b>,"https?://[^/$]+", "</span><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'><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><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:10.0pt;font-family:"Arial","sans-serif";background:white'>TO : </span><span style='font-size:10.0pt;font-family:Wingdings;background:white'>à</span><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:10.0pt;font-family:"Arial","sans-serif";background:white'>set req.http.X-REDIRURL = regsub(<b>req.http.host</b>,"https?://[^/$]+", "</span><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'><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><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'>?<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'>Because when <b>replace req.url with req.http.host</b>, It again stops working.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>And <b>If I don’t do it</b>, the bowser gives an error <b>“Too many redirects”<o:p></o:p></b></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><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><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"'> Travis Crowder [mailto:travis.crowder@spechal.com] <br><b>Sent:</b> Saturday, July 27, 2013 7:53 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></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Check against req.http.Host<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>In vcl_recv:<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><div><p class=MsoNormal>     if(req.http.Host ~ "8.8.8.8") {<o:p></o:p></p></div><div><p class=MsoNormal>         error 750;<o:p></o:p></p></div><div><p class=MsoNormal>     }<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>-Travis Crowder<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><div><p class=MsoNormal>On Jul 27, 2013, at 3:48 PM, Puneet <<a href="mailto:puneet.arora@insticator.com">puneet.arora@insticator.com</a>> wrote:<o:p></o:p></p></div><p class=MsoNormal><br><br><o:p></o:p></p><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";background:white'>Hi all,</span><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'><o:p></o:p></span></p></div><div><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 class=apple-converted-space> </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><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'><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><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><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";background:white'> </span><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";background:white'>Thanks</span><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'><o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";background:white'>Puneet</span><span style='font-size:11.0pt;font-family:"Calibri","sans-serif"'><o:p></o:p></span></p></div><p class=MsoNormal><span style='font-size:13.5pt;font-family:"Helvetica","sans-serif"'>_______________________________________________<br>varnish-misc mailing list<br><a href="mailto:varnish-misc@varnish-cache.org"><span style='color:#954F72'>varnish-misc@varnish-cache.org</span></a><br><a href="https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc"><span style='color:#954F72'>https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc</span></a><o:p></o:p></span></p></div></blockquote></div><p class=MsoNormal><o:p> </o:p></p></div></div></body></html>