Всем привет!
Ребята, прошу помощи в настройке ngx_http_geoip2_module.
Цель: Разрешить доступ к сайту, если IP из UA, RU, DE. Остальным блокировать доступ к сайту.
Nginx установлен с этим модулем.
Nginx -V показывает наличие модуля как динамического.
По ссылке
http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.mmdb.gz скачал архив и распаковал в /usr/local/share/GeoIP/
Ниже приведу конфиг nginx.conf:
Код:
worker_processes 4;
load_module /usr/local/libexec/nginx/ngx_http_geoip2_module.so;
error_log /var/log/nginx/error.log;
events {
worker_connections 1024;
}
http {
include mime.types;
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"';
sendfile on;
keepalive_timeout 65;
geoip2 /usr/local/share/GeoIP/GeoLite2-Country.mmdb {
auto_reload 5m;
$geoip2_data_country_code country iso_code;
}
map $geoip2_data_country_code $country_code_allowed {
default deny;
UA allow;
RU allow;
DE allow;
}
server {
listen 80;
server_name site.com;
server_name _;
if ($country_code_allowed = deny) {
return 444;
}
return 301 https://site.com$request_uri;
access_log /var/log/nginx/access.log main;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/www/nginx-dist;
}
}
server {
listen 443 ssl;
server_name localhost;
server_name _;
server_tokens off;
root /var/ftp/site;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?url=$1;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param GEOIP_COUNTRY_CODE $geoip2_data_country_code;
include fastcgi_params;
}
location ~ \.(sql|js|css|png|jpg|gif|swf|ico|pdf|mov|avi|mp4|fla|zip|rar|gz|gzip|csv|doc|docx|xls|xlsx|ppt|pptx|xml)$ {
try_files $uri =404;
}
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
}
}
При таком конфиге у меня ничего не блокируется.
Подскажите, где я накосячил?
Заранее спасибо всем за помощь!