{"id":2485,"date":"2013-01-25T22:05:45","date_gmt":"2013-01-25T22:05:45","guid":{"rendered":"http:\/\/blog.ed.gs\/?p=2485"},"modified":"2013-01-25T22:05:45","modified_gmt":"2013-01-25T22:05:45","slug":"nginx-multiple-if-statements","status":"publish","type":"post","link":"https:\/\/ed.gs\/2013\/01\/25\/nginx-multiple-if-statements\/","title":{"rendered":"Nginx Multiple If Statements"},"content":{"rendered":"
Nginx doesn’t allow multiple if statements, so if you need to match multiple rules and you’re not checking if files exist then this is how you need to proceed.<\/p>\n
set $posting 0; # Make sure to declare it first to stop any warnings\n \nif ($request_method = POST) { # Check if request method is POST\n set $posting N; # Initially set the $posting variable as N\n}\n \nif ($geoip_country_code ~ (BR|CN|KR|RU|UA) ) { # Here we're using the Nginx GeoIP module to block some spammy countries\n set $posting "${posting}O"; # Set the $posting variable to itself plus the letter O\n}\n \nif ($posting = NO) { # We're looking if both of the above rules are set to spell NO\n return 403; # If it is then let's block them!\n}<\/pre>\nAs you can see we have to use a variable, adding another character at each step and matching the final value with what we want to do.<\/p>\n","protected":false},"excerpt":{"rendered":"
Nginx doesn’t allow multiple if statements, so if you need to match multiple rules and you’re not checking if files exist then this is how you need to proceed. set $posting 0; # Make sure to declare it first to stop any warnings if ($request_method = POST) { # Check if request method is POST […]<\/p>\n","protected":false},"author":2,"featured_media":3497,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ep_exclude_from_search":false},"categories":[32,46],"tags":[],"yoast_head":"\n
Nginx Multiple If Statements - E<\/title>\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n\t\n\n\n\t\n\t\n\t\n