簡體   English   中英

如何在Nginx中設置geoIp的路徑

[英]How to set the path to geoIp in nginx

我正在嘗試在centos6上安裝Nginx GeoIP模塊
我正在使用此指南進行安裝: 如何安裝Nginx GeoIP模塊
但是,當我嘗試在nginx.cof設置GeoIp的路徑時,我遇到了這個問題:

nginx:[emerg] /etc/nginx/nginx.conf中的未知指令“ geoip_country”:7 nginx:
配置文件/etc/nginx/nginx.conf測試失敗

這些是我添加到nginx.conf的行:

geoip_country /usr/local/share/GeoIP/GeoIP.dat;
geoip_city /usr/local/share/GeoIP/GeoLiteCity.dat;

我在Google中搜索了此issu,一個答案是它應該在main{}部分中,但是當我在nginx.conf中插入main{}並在其中插入行時,我看到另一個錯誤說main{}是錯誤的! 我還在其他地方讀到main{}是相同的nginx.conf文件!
我很困惑,有人可以幫我嗎?


[UPDATE]
這是我的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; } 

有什么問題嗎?

geoip_指令需要放置在nginx.conf文件中的http { ... }塊內。 例如:

http {
    geoip_country /usr/local/share/GeoIP/GeoIP.dat;
    geoip_city /usr/local/share/GeoIP/GeoLiteCity.dat;

    server {
        ...
    }
}

有關更多信息,請參見此文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM