title: how Nginx block empty user agent if not from specific ips
body: <p>I'm trying to block with Nginx any request coming from empty user agent if not originated from specific IPs.</p>
  <p>Since Nginx doesn't allow nested ifs, I tried:</p>
  <pre><code>set $precond 0;
  if ( $remote_addr != XX.XX.XX.XX|YY.YY.YY.YY ){set $precond precond+1;}
  if ($http_user_agent ~* &quot;-&quot;) {set $precond precond+1;}
  if ($precond = 2){return 403;}
  </code></pre>
  <p>I placed it at &quot;Additional nginx directives&quot; of the page &quot;Apache &amp; nginx Settings&quot; at Plesk Control Panel.</p>
  <p>I couldn't have the wanted result.</p>
  <p>Can you help please?</p>
  <p>Thank you,</p>