Would you like to learn how to install Apache and deny access from a country? In this tutorial, we are going to configure the Apache server to block the access from a country.
• 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.
Apache – Related Tutorial:
On this page, we offer quick access to a list of tutorials related to Apache.
Tutorial Apache – GEOIP2 database installation
Access the MAXMIND website and create a new account.
Access your account profile and create a new key.
Add the MAXMIND repository to your Ubuntu Linux.
Install the package named GEOIPUPDATE.
Edit the GEOIPUPDATE configuration file.
Insert your account ID and license key.
Here is the file, before our configuration.
Here is the file, after our configuration.
Update the database of GEOIP2.
Verify the GEOIP2 database installation.
Here is the command output.
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.
Install the required packages.
Install the library named LIBMAXMINDDB.
Download the latest version of the Apache module named MOD_MAXMINDDB.
Compile and install the Apache module.
Congratulations! You have finished the MAXMIND module installation on the Apache server.
Tutorial Apache – Blocking access from a country
Enable the required Apache modules.
Edit the Apache configuration file for the website.
Add the following lines to this configuration file.
In our example, we denied access from Brazil and the United States.
Verify the list of country codes.
Here is the file, before our configuration.
Here is the file, after our configuration.
Restart the Apache service.
The Apache server will deny access based on the country of the source IP address.
Here is the command output.
Congratulations! You are able to configure Apache to restrict access to your website based on the country of the request.
Tutorial GEOIP2 – Database update
Create a scheduled task to update the GEOIP2 database.
Here is the file content.
Congratulations! You have configured the GEOIP2 database automatic update.