Tiny Flask server to proxy MaxMind GeoLite requests. Get the estimated city, country, and coordinates of a user's IP.
- Sign up for a free GeoLite API key.
- Once signed up, create a MaxMind license key.
- Within the repo, run
cp .env.example .env. - In the
.envfile, fill in the environment variables with your license key info.
Next, follow the instructions below to run the app.
- Run
docker compose up.
- Install
uv. - Run
uv sync. - Run
uv run python app.py.
Once the app is running, make a request to http://localhost:5050 with a valid public IP address in the X-Forwarded-For header. For example:
curl --location 'localhost:5050' --header 'X-Forwarded-For: 75.219.240.157'You should get a response like:
{
"city": "Brooklyn",
"country_code": "US",
"country_name": "United States",
"ip": "75.219.240.157",
"latitude": 40.6462,
"longitude": -73.9559
}If deploying on a public server behind a reverse proxy, ensure that you set the X-Forwarded-For header to pass along the requestor's IP address to the application. For example on Nginx:
server {
server_name geoip.harrisonliddiard.com;
location / {
proxy_pass http://localhost:5050;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}