Skip to content

Instantly share code, notes, and snippets.

@Coopeh
Created January 25, 2013 19:42
Show Gist options
  • Save Coopeh/4637216 to your computer and use it in GitHub Desktop.
Save Coopeh/4637216 to your computer and use it in GitHub Desktop.
How to use multiple if statements in Nginx
set $posting 0; # Make sure to declare it first to stop any warnings
if ($request_method = POST) { # Check if request method is POST
set $posting N; # Initially set the $posting variable as N
}
if ($geoip_country_code ~ (BR|CN|KR|RU|UA) ) { # Here we're using the Nginx GeoIP module to block some spammy countries
set $posting "${posting}O"; # Set the $posting variable to itself plus the letter O
}
if ($posting = NO) { # We're looking if both of the above rules are set to spell NO
return 403; # If it is then let's block them!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment