Stop users accessing website via IP address

Puneet puneet.arora at insticator.com
Sun Jul 28 05:13:12 CEST 2013


HI Travis,

 

I am trying to redirect the user to the location of my website.

 

For eg. The user enters http://X.X.X.X/login

I want to redirect the user to http://www.mywebsite.com/login

 

In the regular expression I am replacing the HOST NAME i.e. http://X.X.X.X
with http://www.mywebsite.com.

Therefore, I am just setting the header value to
http://www.mywebsite.com/login

And then in the next line

Set , obj.location to : http://www.mywebsite.com/login

 

This was what I intended to accomplish.

 

Thanks

Puneet

From: Travis Crowder [mailto:travis.crowder at spechal.com] 
Sent: Saturday, July 27, 2013 11:04 PM
To: Puneet
Cc: varnish-misc at varnish-cache.org
Subject: Re: Stop users accessing website via IP address

 

Your regular expression is malformed and you don't do any capturing or
replacement in the regsub function so I am not sure what you're trying to
accomplish there.

 

Can you elaborate on what you're trying set this header's value to?

 

-Travis Crowder

 

 

On Jul 27, 2013, at 9:38 PM, Puneet <puneet.arora at insticator.com
<mailto:puneet.arora at insticator.com> > wrote:





HI Travis,

 

Thanks for the reply.

I think that should work.

 

Just one question.

In sub vcl_error() should I also change the

 

set req.http.X-REDIRURL = regsub(req.url,"https?://[^/$]+", "
<http://www.linkedin.com/redirect?url=http%3A%2F%2Fmywebsite%2Ecom&urlhash=5
qRF&_t=tracking_anet> http://mywebsite.com");

TO : -->

set req.http.X-REDIRURL = regsub(req.http.host,"https?://[^/$]+", "
<http://www.linkedin.com/redirect?url=http%3A%2F%2Fmywebsite%2Ecom&urlhash=5
qRF&_t=tracking_anet> http://mywebsite.com");

?

 

Because when replace req.url with req.http.host, It again stops working.

And If I don't do it, the bowser gives an error "Too many redirects"

 

Thanks

Puneet

 

From: Travis Crowder [mailto:travis.crowder at spechal.com <http://spechal.com>
] 
Sent: Saturday, July 27, 2013 7:53 PM
To: Puneet
Cc: varnish-misc at varnish-cache.org <mailto:varnish-misc at varnish-cache.org> 
Subject: Re: Stop users accessing website via IP address

 

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 < <mailto:puneet.arora at insticator.com>
puneet.arora at insticator.com> 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://www.linkedin.com/redirect?url=http%3A%2F%2Fmywebsite%2Ecom&urlhash=5
qRF&_t=tracking_anet> 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
 <mailto:varnish-misc at varnish-cache.org> varnish-misc at varnish-cache.org
 <https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc>
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20130727/0f680cff/attachment-0001.html>


More information about the varnish-misc mailing list