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:
http://forum.nginx.org/read.php?2,45170,45170#msg-45170

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:
http://forum.nginx.org/read.php?2,45170,45596#msg-45596

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:
http://forum.nginx.org/read.php?2,45170,45623#msg-45623

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.

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

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

Cliff