Blocking blank useragent requests

Does anyone know how I can achieve this? I want to block all requests
with blank useragents, however I’m not exactly sure how would I go about
setting that up in nginx’s configuration.

Posted at Nginx Forum:

if ($http_user_agent = “”) { return 403; }

Best regards,
Piotr S. < [email protected] >

Thanks for the response, greatly appreciated :slight_smile: However I’m getting
Unknown directive ‘if’ when trying to add this into my nginx config -
any ideas?

Posted at Nginx Forum:

Hi,

Bob wrote:

Thanks for the response, greatly appreciated :slight_smile: However I’m getting Unknown directive ‘if’ when trying to add this into my nginx config - any ideas?

Is your ‘if’ statement under a server or location block? If not, it
won’t work.

http://wiki.nginx.org/NginxHttpRewriteModule#if

Marcus.

Yeah, the rewrite module wasn’t compiled in. Recompiling nginx with the
http_rewrite_module did the trick!

Posted at Nginx Forum:

On Tue, 2010-01-26 at 00:54 +0200, Marcus C. wrote:

Hi,

Bob wrote:

Thanks for the response, greatly appreciated :slight_smile: However I’m getting Unknown directive ‘if’ when trying to add this into my nginx config - any ideas?

Is your ‘if’ statement under a server or location block? If not, it
won’t work.

Module ngx_http_rewrite_module

Also, as that URL indicates, “if” is part of the rewrite module, so that
must be compiled in.

Cliff