M
M
Monkz2022-01-10 18:33:03
Nginx
Monkz, 2022-01-10 18:33:03

How to return geoip result in nginx?

Good afternoon!
Given: nginx with geoip2 connected.
Is it possible to make it so that when accessing a specific location (for example: /geoip) nginx gives the result of geoip2 work in json ??
I know, you can do something like this, but this is the header, and I want json, or at least to give text:

location /geoip {
    add_header Cache-Control 'no-cache';
    add_header GeoIP-Country-Code $geoip2_data_country_iso_code;
}


Thanks in advance for your reply!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2022-01-10
@Monkz

location /geoip {
    add_header Cache-Control 'no-cache';

    default_type application/json;
    return 200 '{"lol":"$geoip2_data_country_iso_code"}';
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question