我正在使用nginx GeoIP模块来获取服务器的国家/地区位置。 nginx -V命令为我提供了安装的模块列表,我已经在列表中获得了--with-http_geoip_module。下一步是在nginx.conf文件中进行更改。
#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" />';
}
}}
我没有得到这个位置。