Monday, December 17, 2012

White listing IPs on Apache and Varnish

  • Varnish
acl white {
    "localhost";
    "1.1.1.1";
    "5.5.0.0"/16;
    # Add as many IPs as you need here
}

if (req.http.host == "somewhere.example.net") {
if (client.ip ~ white) {
   set req.backend = default;
   return(pipe);
   }
error 403 "Forbidden";
}


  • Apache

<VirtualHost *:8080>
    DocumentRoot /var/www/something
    DirectoryIndex index.php index.html
    ServerName somewhere.example.net
        <Directory "/var/www/somewhere">
                Options FollowSymLinks Indexes
                AllowOverride all
                Order deny,allow
                Deny from all
                Allow from 127.0.0.1
        </Directory>
</VirtualHost>