Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
You can’t perform that action at this time.