A map will be better here; map $http_user_agent $block { default 0; ~*Linux.Android 4\.2\.2 1; ....etc..... } location { if ($block) { return 403; } ......... Posted at Nginx Forum: http://forum.nginx.org/read.php?2,257269,257286#msg-257286