SlideShare a Scribd company logo
1 of 11
HOW TO DISPLAY COUNTRY
CODE IN THE APACHE LOG
USING THE IP2LOCATION
APACHE MODULE
https://www.ip2location.com
INTRODUCTION
• Apache is a popular open-source web server being used on
both the Linux and Windows environment.
PRE-REQUISITES
• Install the apache2-dev package if you don’t have it:
• You can get the IP2Location BIN database file from:
•
• Decompress the BIN file called ip2location
sudo apt-get install apache2-dev
https://www.ip2location.com/database/ip2location (commercial)
OR
https://lite.ip2location.com/ip2location-lite (free LITE version, less
accurate)
INSTALLATION
• We need to get the IP2Location C library and decompress in a
folder called ip2location from the link below:
• Navigate to the IP2Location-C-Library-master sub-folder.
https://github.com/chrislim2888/IP2Location-C-
Library/archive/master.zip
cd IP2Location-C-Library-master
INSTALLATION
• Now, compile the IP2Location C library by running the below
commands.
• Next, download the IP2Location Apache module and
decompress into the ip2location from below link:
sudo autoreconf -i -v --force
sudo ./configure
sudo make
sudo make install
https://github.com/ip2location/ip2location-apache/archive/master.zip
INSTALLATION
• You should now have 2 sub-folders. Navigate to the
ip2location-apache-master folder.
• Compile both IP2Location C library and Apache module
• Add symbolic link to the shared object file
cd ../ip2location-apache-master
sudo apxs2 -i -a -L /usr/local/lib/ -I ../IP2Location-C-Library-
master/libIP2Location/ -l IP2Location -c mod_ip2location.c
sudo ln -s /usr/local/lib/libIP2Location.so.1/usr/lib/libIP2Location.so.1
CONFIGURATION
• Add following lines into the /etc/apache2/apache2.conf file.
Modify the IP2LocationDBFile parameter for your own folder
and BIN filename.
<IfModule mod_ip2location.c>
IP2LocationEnable On
IP2LocationDetectProxy Off
IP2LocationSetmode ENV
IP2LocationDBFile "/home/admin/ip2location/IP-COUNTRY-REGION-
CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-
NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE.BIN"
</IfModule>
CONFIGURATION
• In the file, look for the row below:
• Change it to look like the below:
• Save the file. The above format modification adds another field
to the front of the log entry to show the country code for the
geolocation information of that IP address.
LogFormat "%h %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i""
combined
LogFormat "%{IP2LOCATION_COUNTRY_SHORT}e %h %l %u %t "%r" %>s
%O "%{Referer}i" "%{User-Agent}i"" combined
RESTART APACHE FOR THE ABOVE
SETTINGS TO TAKE EFFECT
• Run the following command to restart.
sudo systemctl restart apache2
• Your log should now have an entry like the below:
MY 175.138.99.179 - - [24/Oct/2019:06:08:02 +0000]
"GET / HTTP/1.1" 200 3380 "-" "Mozilla/5.0 (Windows NT
10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0"
OPEN YOUR BROWSER AND NAVIGATE TO
YOUR WEBPAGE
In this case, the country code is MY for Malaysia.
FOR MORE ARTICLES, PLEASE VISIT
https://blog.ip2location.com

More Related Content

What's hot

PowerPoint Presentation
PowerPoint PresentationPowerPoint Presentation
PowerPoint Presentation
webhostingguy
 
MariaDB with SphinxSE
MariaDB with SphinxSEMariaDB with SphinxSE
MariaDB with SphinxSE
Colin Charles
 
13 DHCP Configuration in Linux
13 DHCP Configuration in Linux13 DHCP Configuration in Linux
13 DHCP Configuration in Linux
Hameda Hurmat
 
Git lab installation guide
Git lab installation guideGit lab installation guide
Git lab installation guide
Raiful Hasan
 
Deploying and maintaining your software with RPM/APT
Deploying and maintaining your software with RPM/APTDeploying and maintaining your software with RPM/APT
Deploying and maintaining your software with RPM/APT
Joshua Thijssen
 

What's hot (20)

Presentation2
Presentation2Presentation2
Presentation2
 
Nagios Conference 2014 - Mike Weber - Expanding NRDS Capabilities on Linux Sy...
Nagios Conference 2014 - Mike Weber - Expanding NRDS Capabilities on Linux Sy...Nagios Conference 2014 - Mike Weber - Expanding NRDS Capabilities on Linux Sy...
Nagios Conference 2014 - Mike Weber - Expanding NRDS Capabilities on Linux Sy...
 
Describing Kafka security in AsyncAPI
Describing Kafka security in AsyncAPIDescribing Kafka security in AsyncAPI
Describing Kafka security in AsyncAPI
 
Hadoop presentation
Hadoop presentationHadoop presentation
Hadoop presentation
 
PowerPoint Presentation
PowerPoint PresentationPowerPoint Presentation
PowerPoint Presentation
 
MariaDB with SphinxSE
MariaDB with SphinxSEMariaDB with SphinxSE
MariaDB with SphinxSE
 
14 FILE Server
14 FILE Server14 FILE Server
14 FILE Server
 
13 DHCP Configuration in Linux
13 DHCP Configuration in Linux13 DHCP Configuration in Linux
13 DHCP Configuration in Linux
 
Useful Kafka tools
Useful Kafka toolsUseful Kafka tools
Useful Kafka tools
 
Percona Live 2012PPT: introduction-to-mysql-replication
Percona Live 2012PPT: introduction-to-mysql-replicationPercona Live 2012PPT: introduction-to-mysql-replication
Percona Live 2012PPT: introduction-to-mysql-replication
 
Bundling Packages and Deploying Applications with RPM
Bundling Packages and Deploying Applications with RPMBundling Packages and Deploying Applications with RPM
Bundling Packages and Deploying Applications with RPM
 
docker build with Ansible
docker build with Ansibledocker build with Ansible
docker build with Ansible
 
Git lab installation guide
Git lab installation guideGit lab installation guide
Git lab installation guide
 
Alfresco Certificates
Alfresco Certificates Alfresco Certificates
Alfresco Certificates
 
aptly: Debian repository management tool
aptly: Debian repository management toolaptly: Debian repository management tool
aptly: Debian repository management tool
 
Snort296x centos6x 2
Snort296x centos6x 2Snort296x centos6x 2
Snort296x centos6x 2
 
Herd your chickens: Ansible for DB2 configuration management
Herd your chickens: Ansible for DB2 configuration managementHerd your chickens: Ansible for DB2 configuration management
Herd your chickens: Ansible for DB2 configuration management
 
Deploying and maintaining your software with RPM/APT
Deploying and maintaining your software with RPM/APTDeploying and maintaining your software with RPM/APT
Deploying and maintaining your software with RPM/APT
 
Deploying Symfony2 app with Ansible
Deploying Symfony2 app with AnsibleDeploying Symfony2 app with Ansible
Deploying Symfony2 app with Ansible
 
NGINX 101 - now with more Docker
NGINX 101 - now with more DockerNGINX 101 - now with more Docker
NGINX 101 - now with more Docker
 

Similar to How to display country code in the apache

Integrating Apache Web Server with Tomcat Application Server
Integrating Apache Web Server with Tomcat Application ServerIntegrating Apache Web Server with Tomcat Application Server
Integrating Apache Web Server with Tomcat Application Server
webhostingguy
 
Integrating Apache Web Server with Tomcat Application Server
Integrating Apache Web Server with Tomcat Application ServerIntegrating Apache Web Server with Tomcat Application Server
Integrating Apache Web Server with Tomcat Application Server
webhostingguy
 
Binary Packaging for HPC with Spack
Binary Packaging for HPC with SpackBinary Packaging for HPC with Spack
Binary Packaging for HPC with Spack
inside-BigData.com
 

Similar to How to display country code in the apache (20)

Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014
 
Integrating Apache Web Server with Tomcat Application Server
Integrating Apache Web Server with Tomcat Application ServerIntegrating Apache Web Server with Tomcat Application Server
Integrating Apache Web Server with Tomcat Application Server
 
Integrating Apache Web Server with Tomcat Application Server
Integrating Apache Web Server with Tomcat Application ServerIntegrating Apache Web Server with Tomcat Application Server
Integrating Apache Web Server with Tomcat Application Server
 
Asian Spirit 3 Day Dba On Ubl
Asian Spirit 3 Day Dba On UblAsian Spirit 3 Day Dba On Ubl
Asian Spirit 3 Day Dba On Ubl
 
Hands on Docker - Launch your own LEMP or LAMP stack
Hands on Docker -  Launch your own LEMP or LAMP stackHands on Docker -  Launch your own LEMP or LAMP stack
Hands on Docker - Launch your own LEMP or LAMP stack
 
Oracle11g On Fedora14
Oracle11g On Fedora14Oracle11g On Fedora14
Oracle11g On Fedora14
 
Oracle11g on fedora14
Oracle11g on fedora14Oracle11g on fedora14
Oracle11g on fedora14
 
Real World Experience of Running Docker in Development and Production
Real World Experience of Running Docker in Development and ProductionReal World Experience of Running Docker in Development and Production
Real World Experience of Running Docker in Development and Production
 
Hands on Docker - Launch your own LEMP or LAMP stack - SunshinePHP
Hands on Docker - Launch your own LEMP or LAMP stack - SunshinePHPHands on Docker - Launch your own LEMP or LAMP stack - SunshinePHP
Hands on Docker - Launch your own LEMP or LAMP stack - SunshinePHP
 
Ruby microservices with Docker - Sergii Koba
Ruby microservices with Docker -  Sergii KobaRuby microservices with Docker -  Sergii Koba
Ruby microservices with Docker - Sergii Koba
 
Binary Packaging for HPC with Spack
Binary Packaging for HPC with SpackBinary Packaging for HPC with Spack
Binary Packaging for HPC with Spack
 
JUDCon 2010 Boston : BoxGrinder
JUDCon 2010 Boston : BoxGrinderJUDCon 2010 Boston : BoxGrinder
JUDCon 2010 Boston : BoxGrinder
 
Infrastructure as code
Infrastructure as codeInfrastructure as code
Infrastructure as code
 
Automação do físico ao NetSecDevOps
Automação do físico ao NetSecDevOpsAutomação do físico ao NetSecDevOps
Automação do físico ao NetSecDevOps
 
Docker orchestration v4
Docker orchestration v4Docker orchestration v4
Docker orchestration v4
 
Docker orchestration
Docker orchestrationDocker orchestration
Docker orchestration
 
02 Hadoop deployment and configuration
02 Hadoop deployment and configuration02 Hadoop deployment and configuration
02 Hadoop deployment and configuration
 
PHP selber bauen
PHP selber bauenPHP selber bauen
PHP selber bauen
 
Docker for Web Developers: A Sneak Peek
Docker for Web Developers: A Sneak PeekDocker for Web Developers: A Sneak Peek
Docker for Web Developers: A Sneak Peek
 
DockerCoreNet
DockerCoreNetDockerCoreNet
DockerCoreNet
 

More from BenHamminton (8)

How to validate an email address syntax
How to validate an email address syntaxHow to validate an email address syntax
How to validate an email address syntax
 
How to use mailbox validator symfony bundle to validate email
How to use mailbox validator symfony bundle to validate emailHow to use mailbox validator symfony bundle to validate email
How to use mailbox validator symfony bundle to validate email
 
How to create map visualization in kibana using ip2location
How to create map visualization in kibana using ip2locationHow to create map visualization in kibana using ip2location
How to create map visualization in kibana using ip2location
 
Preventing click fraud
Preventing click fraudPreventing click fraud
Preventing click fraud
 
What is ship forwarder
What is ship forwarderWhat is ship forwarder
What is ship forwarder
 
10 measures to reduce credit card fraud for Internet Merchants
10 measures to reduce credit card fraud for Internet Merchants10 measures to reduce credit card fraud for Internet Merchants
10 measures to reduce credit card fraud for Internet Merchants
 
How to define email marketing roi
How to define email marketing roiHow to define email marketing roi
How to define email marketing roi
 
How to use ip2 location in r language
How to use ip2 location in r languageHow to use ip2 location in r language
How to use ip2 location in r language
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governance
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Quantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingQuantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation Computing
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 

How to display country code in the apache

  • 1. HOW TO DISPLAY COUNTRY CODE IN THE APACHE LOG USING THE IP2LOCATION APACHE MODULE https://www.ip2location.com
  • 2. INTRODUCTION • Apache is a popular open-source web server being used on both the Linux and Windows environment.
  • 3. PRE-REQUISITES • Install the apache2-dev package if you don’t have it: • You can get the IP2Location BIN database file from: • • Decompress the BIN file called ip2location sudo apt-get install apache2-dev https://www.ip2location.com/database/ip2location (commercial) OR https://lite.ip2location.com/ip2location-lite (free LITE version, less accurate)
  • 4. INSTALLATION • We need to get the IP2Location C library and decompress in a folder called ip2location from the link below: • Navigate to the IP2Location-C-Library-master sub-folder. https://github.com/chrislim2888/IP2Location-C- Library/archive/master.zip cd IP2Location-C-Library-master
  • 5. INSTALLATION • Now, compile the IP2Location C library by running the below commands. • Next, download the IP2Location Apache module and decompress into the ip2location from below link: sudo autoreconf -i -v --force sudo ./configure sudo make sudo make install https://github.com/ip2location/ip2location-apache/archive/master.zip
  • 6. INSTALLATION • You should now have 2 sub-folders. Navigate to the ip2location-apache-master folder. • Compile both IP2Location C library and Apache module • Add symbolic link to the shared object file cd ../ip2location-apache-master sudo apxs2 -i -a -L /usr/local/lib/ -I ../IP2Location-C-Library- master/libIP2Location/ -l IP2Location -c mod_ip2location.c sudo ln -s /usr/local/lib/libIP2Location.so.1/usr/lib/libIP2Location.so.1
  • 7. CONFIGURATION • Add following lines into the /etc/apache2/apache2.conf file. Modify the IP2LocationDBFile parameter for your own folder and BIN filename. <IfModule mod_ip2location.c> IP2LocationEnable On IP2LocationDetectProxy Off IP2LocationSetmode ENV IP2LocationDBFile "/home/admin/ip2location/IP-COUNTRY-REGION- CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN- NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE.BIN" </IfModule>
  • 8. CONFIGURATION • In the file, look for the row below: • Change it to look like the below: • Save the file. The above format modification adds another field to the front of the log entry to show the country code for the geolocation information of that IP address. LogFormat "%h %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i"" combined LogFormat "%{IP2LOCATION_COUNTRY_SHORT}e %h %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i"" combined
  • 9. RESTART APACHE FOR THE ABOVE SETTINGS TO TAKE EFFECT • Run the following command to restart. sudo systemctl restart apache2
  • 10. • Your log should now have an entry like the below: MY 175.138.99.179 - - [24/Oct/2019:06:08:02 +0000] "GET / HTTP/1.1" 200 3380 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:69.0) Gecko/20100101 Firefox/69.0" OPEN YOUR BROWSER AND NAVIGATE TO YOUR WEBPAGE In this case, the country code is MY for Malaysia.
  • 11. FOR MORE ARTICLES, PLEASE VISIT https://blog.ip2location.com