Would you like to learn how to install Apache and deny access from a city? In this tutorial, we are going to configure the Apache server to block the access from a city.

• Ubuntu 18
• Ubuntu 19
• Ubuntu 20
• Apache 2.4.41

In our example, the Apache server is hosting the website WWW.GAMEKING.TIPS.

Copyright © 2018-2021 by Techexpert.tips.
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted in any form or by any means without the prior written permission of the publisher.

Equipment list

The following section presents the list of equipment used to create this tutorial.

As an Amazon Associate, I earn from qualifying purchases.

Tutorial Apache - GEOIP2 database installation

Access the MAXMIND website and create a new account.

Access your account profile and create a new key.

Nginx - GeoIP2 key

Add the MAXMIND repository to your Ubuntu Linux.

Copy to Clipboard

Install the package named GEOIPUPDATE.

Copy to Clipboard

Edit the GEOIPUPDATE configuration file.

Copy to Clipboard

Insert your account ID and license key.

Here is the file, before our configuration.

Copy to Clipboard

Here is the file, after our configuration.

Copy to Clipboard

Update the database of GEOIP2.

Copy to Clipboard

Verify the GEOIP2 database installation.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

You installed the GEOIP2 database for countries and cities.

Congratulations! You have finished the installation of GEOIPUPDATE.

Tutorial Apache - MaxMind module installation

Install the Apache server.

Copy to Clipboard

Install the required packages.

Copy to Clipboard

Install the library named LIBMAXMINDDB.

Copy to Clipboard

Download the latest version of the Apache module named MOD_MAXMINDDB.

Copy to Clipboard

Compile and install the Apache module.

Copy to Clipboard

Congratulations! You have finished the MAXMIND module installation on the Apache server.

Tutorial Apache - Blocking access from a city

Enable the required Apache modules.

Copy to Clipboard

Edit the Apache configuration file for the website.

Copy to Clipboard

Add the following lines to this configuration file.

Copy to Clipboard

In our example, we denied access from cities named BOARDMAN and NOVA IGUAÇU.

Here is the file, before our configuration.

Copy to Clipboard

Here is the file, after our configuration.

Copy to Clipboard

Restart the Apache service.

Copy to Clipboard

The Apache server will deny access based on the city of the source IP address.

From a remote computer in a restricted city, try to access your website.
Copy to Clipboard

Here is the command output.

Copy to Clipboard

Congratulations! You are able to configure Apache to restrict access to your website based on the city of the request.

Tutorial GEOIP2 - Database update

Create a scheduled task to update the GEOIP2 database.

Copy to Clipboard

Here is the file content.

Copy to Clipboard

Congratulations! You have configured the GEOIP2 database automatic update.