I need some help writing an Nginx rule for the WordPress Cookies For Comments plugin. There's an Apache .htaccess rule that seems to block most spam simply by checking for the presence of a cookie before allowing access to the wp-comments-post.php file. If the cookie doesn't exist, you get a 403 error.
The Apache version of the rules is (where "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" is the cookie string):
RewriteCond %{HTTP_COOKIE} !^.*xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.*$
RewriteRule ^wp-comments-post.php - [F,L]
Is there a way to convert this so that it works for Nginx? I've tried a location-based rule, but it doesn't quite work. Any Nginx veterans have suggestions for how to make this work? Here's what I've been trying to work with:
location ~* wp-comments-post.php {
if ($http_cookie !~* "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") {
return 403;
break;
}
}