Sunday, January 25, 2015

Using Varnish to block access to specific folders

If you ever need to block folder or folders using Varnish Cache, here are the simple steps.

Edit  sub vcl_recv and add the following
sub vcl_recv {
  # Ban outside access to #/user, /admin etc
  # works if you : if (req.url ~ "^/user" || req.url ~ "^/admin") {
  if ( (req.url ~ "^/user" || req.url ~ "^/admin" ) && !client.ip ~ yourallowedip) {
      # Have Varnish throw the error directly.
       error 405 "Sorry";
    }
#Other code
#....
}
Create...
acl yourallowedip {
    "1.1.1.1";
}
Restart varnish and you will be good to go.

service restart varnish

It is always good to test your configuration before restarting Varnish. The command to do is below. It there is an error it will let you know otherwise you will get a long display.

varnishd -C -f /etc/varnish/default.vcl

References

Generate PFX file using OPENSSL on Windows

Had a situation where a client needed a PFX with password for a particular setup. This is something I have not done before, so here are the ...