File tree Expand file tree Collapse file tree 7 files changed +95
-0
lines changed Expand file tree Collapse file tree 7 files changed +95
-0
lines changed Original file line number Diff line number Diff line change
1
+ venv /
2
+ iplookup /__pycache__ /
3
+ instance /.geoipupdate.lock
Original file line number Diff line number Diff line change
1
+ # The following AccountID and LicenseKey are required placeholders.
2
+ # For geoipupdate versions earlier than 2.5.0, use UserId here instead of AccountID.
3
+ AccountID 0
4
+ LicenseKey 000000000000
5
+
6
+ # Include one or more of the following edition IDs:
7
+ # * GeoLite2-City - GeoLite 2 City
8
+ # * GeoLite2-Country - GeoLite2 Country
9
+ # For geoipupdate versions earlier than 2.5.0, use ProductIds here instead of EditionIDs.
10
+ EditionIDs GeoLite2-City GeoLite2-Country GeoLite2-ASN
Original file line number Diff line number Diff line change
1
+ 1 . Install the GeoIP2 Python libraries
2
+ pip3 install geoip2
3
+
4
+ 2 . Install the Python flask framework
5
+ pip3 install flask
6
+
7
+ 3 . Install Gunicorn to run flask as a service
8
+ pip3 install gunicorn
9
+
10
+ 4 . Clone the Git to target directory
11
+ git clone <repo_url> /opt/geoip2
12
+
13
+ 5 . Run it Interactively as a test
14
+ cd /opt/geoip2
15
+ gunicorn --pid /run/geoip2.pid -b localhost:5001 iplookup
16
+
17
+ You should now be able to connect to http://localhost:5001
18
+
19
+ Optional setup:
20
+ 1 . Set IPLookup to run as a service
21
+ cp /opt/geoip2/geoip2.service.sample /etc/systemd/system/geoip2.service
22
+ systemctl daemon-reload
23
+ systemctl enable geoip2.service
24
+ systemctl start geoip2.service
25
+
26
+ 2 . Configure Apache2 as a reverse proxy to the service
27
+ cp /opt/geoip2/iplookup.conf.sample /etc/apache2/sites-available/iplookup.conf
28
+ a2ensite iplookup
29
+ systemctl reload apache2
30
+
31
+ 3 . Refresh the Maxmind GeoIP DBs regularly
32
+ apt install geoipupdate
33
+ cp /opt/geoip2/GeoIP.conf.sample /etc/GeoIP.conf
34
+ cp /opt/geoip2/geoipupdate.crond.sample /etc/cron.d/geoipupdate
35
+
Original file line number Diff line number Diff line change
1
+ # IPLookup
2
+
3
+ This code runs an API that when called with and IPv4 or IPv6 address will return the GeoLocation details
4
+ e.g
5
+
6
+ http://localhost:5001/128.184.1.1
7
+ {"response":{"city":{"geoname_id":2169236,"names":{"en":"Deakin"}}}}}
Original file line number Diff line number Diff line change
1
+ [Unit]
2
+ Description = Gunicorn instance to serve GeoIP2 Lookup
3
+ After = network.target
4
+
5
+ [Service]
6
+ user = www-data
7
+ group = www-data
8
+ WorkingDirectory = /opt/geoip2
9
+ PIDFile=/run/geoip2.pid
10
+ ExecStart = /usr/local/bin/gunicorn --pid /run/geoip2.pid -b localhost:5001 iplookup
11
+ ExecReload=/bin/kill -s HUP $MAINPID
12
+ ExecStop=/bin/kill -s TERM $MAINPID
13
+
14
+ [Install]
15
+ WantedBy = multi-user.target
16
+
Original file line number Diff line number Diff line change
1
+ # Sample cron file to update Maxmind GeoIP2 DB files regularly
2
+ 45 12 * * 3 root /usr/bin/geoipupdate -d /opt/geoip2/instance
3
+
4
+
Original file line number Diff line number Diff line change
1
+ <VirtualHost *:80>
2
+ ProxyPreserveHost On
3
+
4
+ ServerName iplookup.mydomain
5
+
6
+ Alias /static /opt/geoip2/iplookup/static
7
+
8
+ <Directory /opt/geoip2/iplookup/static>
9
+ Options Indexes FollowSymLinks MultiViews
10
+ AllowOverride None
11
+ Require all granted
12
+ </Directory>
13
+
14
+ <Location /static>
15
+ ProxyPass !
16
+ </Location>
17
+
18
+ ProxyPass / http://127.0.0.1:5001/
19
+ ProxyPassReverse / http://127.0.0.1:5001/
20
+ </VirtualHost>
You can’t perform that action at this time.
0 commit comments