title: How to block a specific user agent in nginx config
body: <p>How do I block a user agent using nginx.
  so far I have something like this:</p>
  
  <pre><code>if ($http_user_agent = "Mozilla/5.0 (Linux; Android 4.2.2; SGH-M919 Build/JDQ39) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.169 Mobile Safari/537.22") {
  return 403;}
  </code></pre>
  
  <p>this is from a similar thread on this stack overflow.</p>
  
  <p>I run nginx as a reverse proxy for cherrypy server. I intend to filter a certain user agent using nginx alone but the above code doesn't work on my server.</p>
  
  <p>is that the correct way to do this?
  It wasn't included in any block in the nginx config. Should I add it to the "http" block or the "server" block</p>