<div dir="ltr">I am not sure if it is my email but it looks like you are passing HTML in the REDIRECT URL.<div><br></div><div style>The REDIRECT URL should be just a URL. Try a simple URL like <a href="http://www.yahoo.com">http://www.yahoo.com</a> first. Then work on your regsub statement to set the right URL.</div>
<div style><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Jul 27, 2013 at 9:38 PM, <span dir="ltr"><<a href="mailto:varnish-misc-request@varnish-cache.org" target="_blank">varnish-misc-request@varnish-cache.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Send varnish-misc mailing list submissions to<br>
<a href="mailto:varnish-misc@varnish-cache.org">varnish-misc@varnish-cache.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<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>
or, via email, send a message with subject or body 'help' to<br>
<a href="mailto:varnish-misc-request@varnish-cache.org">varnish-misc-request@varnish-cache.org</a><br>
<br>
You can reach the person managing the list at<br>
<a href="mailto:varnish-misc-owner@varnish-cache.org">varnish-misc-owner@varnish-cache.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of varnish-misc digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
1. Re: Stop users accessing website via IP address<br>
(Hugo Cisneiros (Eitch))<br>
2. Re: Stop users accessing website via IP address (Travis Crowder)<br>
3. RE: Stop users accessing website via IP address (Puneet)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Sat, 27 Jul 2013 18:28:57 -0300<br>
From: "Hugo Cisneiros (Eitch)" <<a href="mailto:hugo.cisneiros@gmail.com">hugo.cisneiros@gmail.com</a>><br>
To: "<a href="mailto:varnish-misc@varnish-cache.org">varnish-misc@varnish-cache.org</a>" <<a href="mailto:varnish-misc@varnish-cache.org">varnish-misc@varnish-cache.org</a>><br>
Subject: Re: Stop users accessing website via IP address<br>
Message-ID:<br>
<CA+KACLkCCfpK2XmM4-vaxOW2b=<a href="mailto:XBL-nbgadgt7FE3XejfWA6cw@mail.gmail.com">XBL-nbgadgt7FE3XejfWA6cw@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="iso-8859-1"<br>
<br>
On Sat, Jul 27, 2013 at 5:48 PM, Puneet <<a href="mailto:puneet.arora@insticator.com">puneet.arora@insticator.com</a>> wrote:<br>
<br>
> I want to stop the users accessing my website via IP address.<br>
><br>
> I am using varnish as cache.<br>
> I have the following code in place but it is not working.<br>
><br>
> In vcl_recv() {<br>
> if(req.url ~ "XX.XX.XXX.XXX") {<br>
> error 750 "Moved Permanently";<br>
> } }<br>
><br>
<br>
In vcl_recv, you're comparting the IP address with the request URL<br>
(req.url), which is wrong. You should compare with client.ip, as it<br>
represents the user's IP address.<br>
<br>
Anyway, a much better approach in my opinion is the code:<br>
<br>
# list of forbidden ips<br>
acl forbidden {<br>
"192.168.0.1",<br>
"192.168.0.2",<br>
"XXX.XXX.XXX.XXX"<br>
}<br>
<br>
sub vcl_recv {<br>
if (client.ip ~ forbidden) {<br>
error 301 "<a href="http://mywebsite.com" target="_blank">http://mywebsite.com</a>";<br>
}<br>
}<br>
<br>
sub vcl_error {<br>
set obj.http.Content-Type = "text/html; charset=utf-8";<br>
set obj.http.Retry-After = "5";<br>
<br>
# we deal with redirects here<br>
if (obj.status == 301) {<br>
set obj.http.Location = obj.response;<br>
set obj.response = "Moved Temporarily";<br>
return (deliver);<br>
}<br>
<br>
if (obj.status == 301){<br>
set obj.http.Location = obj.response;<br>
set obj.response = "Moved Permanently";<br>
return (deliver);<br>
}<br>
}<br>
<br>
This way you can update the ACL to multiple IP addresses and they'll be all<br>
redirected to <a href="http://mywebsite.com" target="_blank">mywebsite.com</a>.<br>
<br>
--<br>
[]'s<br>
Hugo<br>
<a href="http://www.devin.com.br" target="_blank">www.devin.com.br</a><br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20130727/8ceb19b3/attachment-0001.html" target="_blank">https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20130727/8ceb19b3/attachment-0001.html</a>><br>
<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Sat, 27 Jul 2013 18:53:11 -0500<br>
From: Travis Crowder <<a href="mailto:travis.crowder@spechal.com">travis.crowder@spechal.com</a>><br>
To: Puneet <<a href="mailto:puneet.arora@insticator.com">puneet.arora@insticator.com</a>><br>
Cc: <a href="mailto:varnish-misc@varnish-cache.org">varnish-misc@varnish-cache.org</a><br>
Subject: Re: Stop users accessing website via IP address<br>
Message-ID: <<a href="mailto:A89915AA-A7FE-432D-90CD-E8B6BF12A105@spechal.com">A89915AA-A7FE-432D-90CD-E8B6BF12A105@spechal.com</a>><br>
Content-Type: text/plain; charset="us-ascii"<br>
<br>
Check against req.http.Host<br>
<br>
In vcl_recv:<br>
<br>
if(req.http.Host ~ "8.8.8.8") {<br>
error 750;<br>
}<br>
<br>
-Travis Crowder<br>
<br>
On Jul 27, 2013, at 3:48 PM, Puneet <<a href="mailto:puneet.arora@insticator.com">puneet.arora@insticator.com</a>> wrote:<br>
<br>
> Hi all,<br>
><br>
> I want to stop the users accessing my website via IP address.<br>
> I am using varnish as cache.<br>
> I have the following code in place but it is not working.<br>
><br>
> In vcl_recv() {<br>
> if(req.url ~ "XX.XX.XXX.XXX") {<br>
> error 750 "Moved Permanently";<br>
> } }<br>
><br>
> And in vcl_error()<br>
> sub vcl_error {<br>
> if (obj.status == 750) {<br>
> set req.http.X-REDIRURL = regsub(req.url,"https?://[^/$]+", "<a href="http://mywebsite.com" target="_blank">http://mywebsite.com</a>");<br>
> set obj.http.Location = req.http.X-REDIRURL;<br>
> set obj.status = 301;<br>
> unset req.http.X-REDIRURL;<br>
> return(deliver);<br>
> }<br>
><br>
> But this does not redirect the user to the website, instead it delivers the page.<br>
> Can anyone tell what I am missing?<br>
><br>
> Thanks<br>
> Puneet<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>
<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20130727/da02d31d/attachment-0001.html" target="_blank">https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20130727/da02d31d/attachment-0001.html</a>><br>
<br>
------------------------------<br>
<br>
Message: 3<br>
Date: Sat, 27 Jul 2013 22:38:24 -0400<br>
From: Puneet <<a href="mailto:puneet.arora@insticator.com">puneet.arora@insticator.com</a>><br>
To: "'Travis Crowder'" <<a href="mailto:travis.crowder@spechal.com">travis.crowder@spechal.com</a>><br>
Cc: <a href="mailto:varnish-misc@varnish-cache.org">varnish-misc@varnish-cache.org</a><br>
Subject: RE: Stop users accessing website via IP address<br>
Message-ID: <005701ce8b3b$88e6ee10$9ab4ca30$@<a href="http://insticator.com" target="_blank">insticator.com</a>><br>
Content-Type: text/plain; charset="us-ascii"<br>
<br>
HI Travis,<br>
<br>
<br>
<br>
Thanks for the reply.<br>
<br>
I think that should work.<br>
<br>
<br>
<br>
Just one question.<br>
<br>
In sub vcl_error() should I also change the<br>
<br>
<br>
<br>
set req.http.X-REDIRURL = regsub(req.url,"https?://[^/$]+", "<br>
<<a href="http://www.linkedin.com/redirect?url=http%3A%2F%2Fmywebsite%2Ecom&urlhash=5
qRF&_t=tracking_anet" target="_blank">http://www.linkedin.com/redirect?url=http%3A%2F%2Fmywebsite%2Ecom&urlhash=5<br>
qRF&_t=tracking_anet</a>> <a href="http://mywebsite.com" target="_blank">http://mywebsite.com</a>");<br>
<br>
TO : --><br>
<br>
set req.http.X-REDIRURL = regsub(req.http.host,"https?://[^/$]+", "<br>
<<a href="http://www.linkedin.com/redirect?url=http%3A%2F%2Fmywebsite%2Ecom&urlhash=5
qRF&_t=tracking_anet" target="_blank">http://www.linkedin.com/redirect?url=http%3A%2F%2Fmywebsite%2Ecom&urlhash=5<br>
qRF&_t=tracking_anet</a>> <a href="http://mywebsite.com" target="_blank">http://mywebsite.com</a>");<br>
<br>
?<br>
<br>
<br>
<br>
Because when replace req.url with req.http.host, It again stops working.<br>
<br>
And If I don't do it, the bowser gives an error "Too many redirects"<br>
<br>
<br>
<br>
Thanks<br>
<br>
Puneet<br>
<br>
<br>
<br>
From: Travis Crowder [mailto:<a href="mailto:travis.crowder@spechal.com">travis.crowder@spechal.com</a>]<br>
Sent: Saturday, July 27, 2013 7:53 PM<br>
To: Puneet<br>
Cc: <a href="mailto:varnish-misc@varnish-cache.org">varnish-misc@varnish-cache.org</a><br>
Subject: Re: Stop users accessing website via IP address<br>
<br>
<br>
<br>
Check against req.http.Host<br>
<br>
<br>
<br>
In vcl_recv:<br>
<br>
<br>
<br>
if(req.http.Host ~ "8.8.8.8") {<br>
<br>
error 750;<br>
<br>
}<br>
<br>
<br>
<br>
-Travis Crowder<br>
<br>
<br>
<br>
On Jul 27, 2013, at 3:48 PM, Puneet <<a href="mailto:puneet.arora@insticator.com">puneet.arora@insticator.com</a><br>
<mailto:<a href="mailto:puneet.arora@insticator.com">puneet.arora@insticator.com</a>> > wrote:<br>
<br>
<br>
<br>
<br>
<br>
Hi all,<br>
<br>
<br>
I want to stop the users accessing my website via IP address.<br>
I am using varnish as cache.<br>
I have the following code in place but it is not working.<br>
<br>
In vcl_recv() {<br>
if(req.url ~ "XX.XX.XXX.XXX") {<br>
error 750 "Moved Permanently";<br>
} }<br>
<br>
And in vcl_error()<br>
sub vcl_error {<br>
if (obj.status == 750) {<br>
set req.http.X-REDIRURL = regsub(req.url,"https?://[^/$]+", "<br>
<<a href="http://www.linkedin.com/redirect?url=http%3A%2F%2Fmywebsite%2Ecom&urlhash=5
qRF&_t=tracking_anet" target="_blank">http://www.linkedin.com/redirect?url=http%3A%2F%2Fmywebsite%2Ecom&urlhash=5<br>
qRF&_t=tracking_anet</a>> <a href="http://mywebsite.com" target="_blank">http://mywebsite.com</a>");<br>
set obj.http.Location = req.http.X-REDIRURL;<br>
set obj.status = 301;<br>
unset req.http.X-REDIRURL;<br>
return(deliver);<br>
}<br>
<br>
But this does not redirect the user to the website, instead it delivers the<br>
page.<br>
Can anyone tell what I am missing?<br>
<br>
<br>
<br>
Thanks<br>
<br>
Puneet<br>
<br>
_______________________________________________<br>
varnish-misc mailing list<br>
<mailto:<a href="mailto:varnish-misc@varnish-cache.org">varnish-misc@varnish-cache.org</a>> <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>
<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>
<br>
<br>
<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20130727/21c9f677/attachment.html" target="_blank">https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20130727/21c9f677/attachment.html</a>><br>
<br>
------------------------------<br>
<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>
<br>
End of varnish-misc Digest, Vol 88, Issue 17<br>
********************************************<br>
</blockquote></div><br></div>