Welcome! Log In Create A New Profile

Advanced

GeoIP only with the POST method

Posted by sgaduuw 
GeoIP only with the POST method
January 04, 2011 06:32PM
Greetings!

In my neverending struggle with comment-spam, I've decided to use GeoIP to block access from several countries. So far, I have only been able to block [b]all[/b] methods with the following piece of config:
[code]geoip_country /etc/nginx/GeoIP.dat;

if ($geoip_country_code ~ "BR|CN|KR") {
return 403;
}[/code]
This works pretty well, but I think it is like killing ants with a nuclear missile. I would like the GeoIP checks to be triggered [b]only[/b] when the POST method is used. This way people still have access to the content of the site.

I have tried a few options that seemed somewhat logical to me:
[code]if ($request_method ~ ^POST$ && $geoip_country_code ~ "BR|CN|KR") {[/code]
and
[code]
if ($request_method ~ ^POST$ ) {
if ($geoip_country_code ~ "BR|CN|KR") {
return 403;
}
}[/code]
Neither worked.

Is what I am trying to do possible at all? If so, how do I achieve this?

Thanks,
Eelco
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 126
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready