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.