GeoIP lookup
apt install mmdb-bin geoipupdate angie-module-geoip2
mmdblookup --ip 2603:1010:200::32c --file /var/lib/GeoIP/GeoLite2-Country.mmdb country iso_code
"AU" <utf8_string>
mmdblookup --ip 52.147.37.48 --file /var/lib/GeoIP/GeoLite2-Country.mmdb country names en
"Australia" <utf8_string>
To see the full nginx / angie config use the -T switch
angie -T | sudo tee yourconf
nginx -T | sudo tee yourconf
This is the full angie config from a test I've been doing. I want to be able to deny access to /wp-login.php and /wp-admin/* from everywhere but allow certain countries, deny any IP's or range of IP's or whitelist certain IP's
# configuration file /etc/angie/angie.conf:
user angie;
worker_processes auto;
worker_rlimit_nofile 65536;
error_log /var/log/angie/error.log notice;
pid /run/angie.pid;
# load modules
include modules.d/*.conf;
events {
worker_connections 65536;
}
http {
geo $ip_allowed {
# 0 = false, 1 = true
default 0; # IP NOT allowed 0 = false
#10.197.3.0/24 1; # IP allowed true
#10.197.3.113 1;
}
geo $blacklisted {
default 0;
#10.197.3.0/24 1;
}
geoip2 /var/lib/GeoIP/GeoLite2-Country.mmdb {
auto_reload 1h;
$geoip2_country_code source=$http_x_forwarded_for country iso_code;
$geoip2_country_name source=$http_x_forwarded_for country names en;
}
map $geoip2_country_code $country_allowed {
default 0;
#"" 1;
AU 1;
}
map "$ip_allowed:$country_allowed:$blacklisted" $denied {
default 1; # denied true
"0:1:0" 0;
"1:0:0" 0; # IP allow $denied = false
"1:1:0" 0; # IP allowed, country allowed, not blacklisted = false
"~^[0-1]:[0-1]:1$" 1; # block anything that is blacklisted
}
# rate limiting
limit_req_zone $binary_remote_addr zone=login_limit:10m rate=1r/s;
# Optional: Return 429 instead of default 503
limit_req_status 429;
include /etc/angie/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"';
log_format extended '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" rt="$request_time" '
'"$http_user_agent" "$http_x_forwarded_for" '
'h="$host" sn="$server_name" ru="$request_uri" u="$uri" '
'ucs="$upstream_cache_status" ua="$upstream_addr" us="$upstream_status" '
'uct="$upstream_connect_time" urt="$upstream_response_time"';
access_log /var/log/angie/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/angie/http.d/*.conf;
}
#stream {
# include /etc/angie/stream.d/*.conf;
#}
# configuration file /etc/angie/modules.d/echo.conf:
load_module modules/ngx_http_echo_module.so;
# configuration file /etc/angie/modules.d/geoip2.conf:
load_module modules/ngx_http_geoip2_module.so;
# configuration file /etc/angie/mime.types:
types {
text/html html htm shtml;
text/css css;
text/xml xml;
image/gif gif;
image/jpeg jpeg jpg;
application/javascript js;
application/atom+xml atom;
application/rss+xml rss;
text/mathml mml;
text/plain txt;
text/vnd.sun.j2me.app-descriptor jad;
text/vnd.wap.wml wml;
text/x-component htc;
image/avif avif;
image/bmp bmp;
image/png png;
image/svg+xml svg svgz;
image/tiff tif tiff;
image/vnd.wap.wbmp wbmp;
image/webp webp;
image/x-icon ico;
image/x-jng jng;
font/woff woff;
font/woff2 woff2;
application/java-archive jar war ear;
application/json json;
application/mac-binhex40 hqx;
application/msword doc;
application/pdf pdf;
application/postscript ps eps ai;
application/rtf rtf;
application/vnd.apple.mpegurl m3u8;
application/vnd.debian.binary-package deb udeb;
application/vnd.google-earth.kml+xml kml;
application/vnd.google-earth.kmz kmz;
application/vnd.ms-excel xls;
application/vnd.ms-fontobject eot;
application/vnd.ms-powerpoint ppt;
application/vnd.oasis.opendocument.graphics odg;
application/vnd.oasis.opendocument.presentation odp;
application/vnd.oasis.opendocument.spreadsheet ods;
application/vnd.oasis.opendocument.text odt;
application/vnd.openxmlformats-officedocument.presentationml.presentation
pptx;
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
xlsx;
application/vnd.openxmlformats-officedocument.wordprocessingml.document
docx;
application/vnd.rar rar;
application/vnd.wap.wmlc wmlc;
application/wasm wasm;
application/x-7z-compressed 7z;
application/x-cocoa cco;
application/x-java-archive-diff jardiff;
application/x-java-jnlp-file jnlp;
application/x-makeself run;
application/x-perl pl pm;
application/x-pilot prc pdb;
application/x-redhat-package-manager rpm;
application/x-sea sea;
application/x-shockwave-flash swf;
application/x-stuffit sit;
application/x-tcl tcl tk;
application/x-x509-ca-cert der pem crt;
application/x-xpinstall xpi;
application/xhtml+xml xhtml;
application/xspf+xml xspf;
application/zip zip;
application/octet-stream bin exe dll;
application/octet-stream dmg;
application/octet-stream iso img;
application/octet-stream msi msp msm;
audio/midi mid midi kar;
audio/mpeg mp3;
audio/ogg ogg;
audio/x-m4a m4a;
audio/x-realaudio ra;
video/3gpp 3gpp 3gp;
video/mp2t ts;
video/mp4 mp4;
video/mpeg mpeg mpg;
video/quicktime mov;
video/webm webm;
video/x-flv flv;
video/x-m4v m4v;
video/x-mng mng;
video/x-ms-asf asx asf;
video/x-ms-wmv wmv;
video/x-msvideo avi;
}
# configuration file /etc/angie/http.d/web1.conf:
server {
listen 80 default_server;
listen 443 ssl default_server;
server_name _;
ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem;
ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key;
index index.php;
#access_log /var/log/angie/host.access.log main;
root /home/web1/web;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
#location /out/ {
# default_type text/html;
# echo "ip = $remote_addr";
# echo "code = $geoip2_country_code";
# echo "name = $geoip2_country_name";
#}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/angie/html;
internal;
}
error_page 403 /403.html;
location = /403.html {
# allow all;
# root /var/www/html;
root /usr/share/angie/html;
internal;
}
location ~ /wp-admin/ {
if ( $denied ) {
return 403;
}
fastcgi_index index.php;
include toggen-php-fpm.conf;
}
location = /wp-login.php {
if ( $denied ) {
return 403;
}
limit_req zone=login_limit burst=5 nodelay;
include toggen-php-fpm.conf;
}
location ~ \.php$ {
include toggen-php-fpm.conf;
}
# deny access to .htaccess files, if Apache's document root
# concurs with angie's one
#
location ~ /\. {
deny all;
}
}
# configuration file /etc/angie/toggen-php-fpm.conf:
fastcgi_intercept_errors on;
include fastcgi_params;
fastcgi_pass unix:/var/run/php/web1.sock;
# configuration file /etc/angie/fastcgi_params:
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $upstream_request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REQUEST_SCHEME $scheme;
fastcgi_param HTTPS $https if_not_empty;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE Angie/$angie_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;

0 Comments