Require ip x.x.x.x not working in Apache 2.4

apache-2.4

I edited my apache2.conf (on Ubuntu) to restrict access to all except from one IP, but I still can access from other IPs. Below is my configuration:

<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require ip x.x.x.x
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require ip x.x.x.x
</Directory>

authz_core module is loaded, so is there something wrong? Thanks.

Best Answer

Example of access restriction from IP addresses for Apache 2.4:

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    <IfModule mod_authz_core.c>
      <RequireAny>
        Require ip 127.0.0.1
        Require ip ::1
        Require ip x.x.x.x
      </RequireAny>
    </IfModule> 
</Directory>

Don't forget to restart apache service by running this command:

service httpd restart

Also don't use directory / for security reasons.