ubuntu 16.04 nginx 版本 1.12.1 中的未知指令“geoip_country”

ubuntu 16.04 nginx 版本 1.12.1 中的未知指令“geoip_country”

我已经使用 chef 安装了 geoip_country。手动尝试了相同的操作,但结果是一样的。

出现错误:

nginx -t
nginx: [emerg] unknown directive "geoip_country" in /etc/nginx/nginx.conf:12
nginx: configuration file /etc/nginx/nginx.conf test failed

这是我使用的版本:

nginx -v
nginx version: nginx/1.12.1

我的 nginx 配置文件:

/etc/nginx/nginx.conf
user www-data;
worker_processes 4;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;
events {
  worker_connections  1024;
}

http {

 geoip_country /etc/nginx/geoip/GeoIP.dat; # the country IP database
 geoip_city /etc/nginx/geoip/GeoLiteCity.dat; # the city IP database

  include       /etc/nginx/mime.types;
  default_type  application/octet-stream;
  charset_types text/css text/plain text/vnd.wap.wml application/javascript application/json application/rss+xml application/xml;


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

  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;

  keepalive_requests 100;
  keepalive_timeout  65;


  gzip  on;
  gzip_http_version 1.0;
  gzip_comp_level 2;
  gzip_proxied any;
  gzip_vary off;
  gzip_types text/plain text/css application/x-javascript text/xml application/xml application/rss+xml application/atom+xml image/svg+xml text/javascript application/javascript application/json text/mathml;
  gzip_min_length  1000;
  gzip_disable     "MSIE [1-6]\.";


  variables_hash_max_size 1024;
  variables_hash_bucket_size 64;
  server_names_hash_bucket_size 64;
  types_hash_max_size 2048;
  types_hash_bucket_size 64;
  client_max_body_size 128M;



  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-enabled/*;
}

以下是配置 geoip 的步骤

mkdir /etc/nginx/geoip
cd /etc/nginx/geoip
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
gunzip GeoIP.dat.gz
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
gunzip GeoLiteCity.dat.gz

答案1

只需安装包“nginx-full”即可解决该问题。

apt-get install nginx-full

相关内容