3

I am using nginx GeoIP module to get the country location of the server. The nginx -V command provide me with the list of modules installed and I am already getting --with-http_geoip_module in the list. The next step was to make changes in nginx.conf file.

    #nginx.conf file
    #user  nginx;
    worker_processes  1;

    #error_log  /var/log/nginx/error.log warn;
    #pid        /var/run/nginx.pid;


    events {
        worker_connections  1024;
    }

    http {
        include       /etc/nginx/mime.types;
        include       /etc/nginx/fastcgi_params;
       default_type  application/octet-stream;

        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"'
                          'geoip_area_code: $geoip_area_code, geoip_city: $geoip_city, geoip_city_continent_code: $geoip_city_continent_code, geoip_city_country_code: $geoip_city_country_code, geoip_city_country_code3: $geoip_city_country_code3, geoip_city_country_name: $geoip_city_country_name, geoip_country_code: $geoip_country_code, geoip_country_code3: $geoip_country_code3, geoip_country_name: $geoip_country_name, geoip_dma_code: $geoip_dma_code, geoip_latitude: $geoip_latitude, geoip_longitude: $geoip_longitude, geoip_org: $geoip_org, geoip_postal_code: $geoip_postal_code, geoip_region: $geoip_region, geoip_region_name: $geoip_region_name';

        access_log  /var/log/nginx/access.log  main;

        sendfile        on;
        tcp_nopush     on;

        keepalive_timeout  65;


        #gzip  on;



       geoip_country /etc/nginx/geoip/GeoIP.dat;
       geoip_city    /etc/nginx/geoip/GeoLiteCity.dat;

       map $geoip_country_code $allowed_country {
            default no;
            in   yes;
    }
       server {
            listen 8075;
            server_name localhost;


      location / {



        set $location $geoip_city_country_name;

        if ($geoip_city)
        {
            set $location "$geoip_city, $geoip_city_country_name";
        }

        set $map "http://maps.google.com/maps/api/staticmap?center=$geoip_latitude,$geoip_longitude&zoom=12&size=640x250&markers=$geoip_latitude,$geoip_longitude&sensor=false";

        sub_filter IP_ADDRESS_PLACEHOLDER</h3>
        '$remote_addr</h3><p><strong>Your location:</strong> $location</p><p><strong>Latitude:</strong> $geoip_latitude</p><p><strong>Longitude:</strong> $geoip_longitude</p><img alt="Geolocation" src="$map" />';
       }
    }}
    

I am not getting the location.

0 Answers0