security - Nginx block POST for certain countries -
i have reverse proxy nginx tomcat.
my goal ban total access countries , ban post countries except one.
total access ban countries can achieved via iptables @ kernel level. easy task.
my dilemma how ban post countries except one. rest of them can see website (get) don't want them create accounts, or post data.
i filter listing forms use post, many.
is way filter nginx post?
thank you
geo $ip_country { ranges; default zz; include /usr/local/nginx/conf/ip_country.conf; } set $method_country $request_method$ip_country; if ($method_country ~ "post(?!au)") { return 405; }
ip_country.conf format like:
0.0.0.0-0.255.255.255 eu; 1.0.0.0-1.0.0.255 au; 1.0.1.0-1.0.3.255 cn; 1.0.4.0-1.0.7.255 au; 1.0.8.0-1.0.15.255 cn; 1.0.16.0-1.0.31.255 jp; 1.0.32.0-1.0.63.255 cn; 1.0.64.0-1.0.127.255 jp; 1.0.128.0-1.0.255.255 th; 1.1.0.0-1.1.0.255 cn; ...
and use $ip_country
value inside scripts with:
fastcgi_param ip_country $ip_country;
Comments
Post a Comment