【发布时间】:2017-09-24 16:25:20
【问题描述】:
我正在尝试在 centos6 上安装 Nginx GeoIP 模块。
我正在使用本指南来安装它:
How to install Nginx GeoIP module
但是当我尝试在nginx.cof中设置GeoIp的路径时遇到了这个问题:
nginx:[emerg] 未知指令“geoip_country”在 /etc/nginx/nginx.conf:7 nginx:
配置文件 /etc/nginx/nginx.conf 测试失败
这些是我添加到nginx.conf 的行:
geoip_country /usr/local/share/GeoIP/GeoIP.dat;
geoip_city /usr/local/share/GeoIP/GeoLiteCity.dat;
我在谷歌搜索了这个问题,一个答案是它应该在main{}
部分,但是当我在 nginx.conf 中插入 main{} 并在其中插入行时,我看到另一个错误说 main{} 是错误的!我还在其他地方读到main{} 是同一个 nginx.conf 文件!
我很困惑,谁能帮我解决这个问题?
[更新]
这是我的 nginx.conf 中的 http 部分:
http {
include /etc/nginx/mime.types;
# For user configurations not maintained by DirectAdmin. Empty by default.
include /etc/nginx/nginx-includes.conf;
# Supplemental configuration
include /etc/nginx/nginx-modsecurity-enable.conf;
include /etc/nginx/nginx-defaults.conf;
include /etc/nginx/nginx-gzip.conf;
include /etc/nginx/directadmin-ips.conf;
include /etc/nginx/directadmin-settings.conf;
include /etc/nginx/nginx-vhosts.conf;
include /etc/nginx/directadmin-vhosts.conf;
geoip_country /usr/local/share/GeoIP/GeoIP.dat;
geoip_city /usr/local/share/GeoIP/GeoLiteCity.dat;
# Set php-fpm geoip variables
fastcgi_param GEOIP_COUNTRY_CODE $geoip_country_code;
fastcgi_param GEOIP_COUNTRY_CODE3 $geoip_country_code3;
fastcgi_param GEOIP_COUNTRY_NAME $geoip_country_name;
fastcgi_param GEOIP_CITY_COUNTRY_CODE $geoip_city_country_code;
fastcgi_param GEOIP_CITY_COUNTRY_CODE3 $geoip_city_country_code3;
fastcgi_param GEOIP_CITY_COUNTRY_NAME $geoip_city_country_name;
fastcgi_param GEOIP_REGION $geoip_region;
fastcgi_param GEOIP_CITY $geoip_city;
fastcgi_param GEOIP_POSTAL_CODE $geoip_postal_code;
fastcgi_param GEOIP_CITY_CONTINENT_CODE $geoip_city_continent_code;
fastcgi_param GEOIP_LATITUDE $geoip_latitude;
fastcgi_param GEOIP_LONGITUDE $geoip_longitude;
}
有什么问题吗?
【问题讨论】:
-
你可能需要
load_module,如果它不是include-ed 在配置文件的其他地方。
标签: php nginx geolocation geoip maxmind