Marcos Bianchi
Marcos Bianchi

Reputation: 45

Nginx Block User-Agent "-"

I'm getting some kind of access that is causing problems on my server:

172.68.28.210 - - [03/Jul/2016:13:41:06 -0300] " "GET / HTTP/1.1" 502 166 "-" "-"

I would like to block even the $HTTP_USER_AGENT, made this attempt did not work.

if ($http_user_agent = "-") {
        return 403;
    }

Someone would know what's wrong?

Upvotes: 2

Views: 3183

Answers (1)

cnst
cnst

Reputation: 27218

That is because the $http_user_agent variable may have different value depending on the context.

If the header is absent in the request, then it'll present itself as - in your access_log, all the while still being just empty within your if-statement.

Thus, perhaps the following is what you want instead:

if ($http_user_agent = "") {
    return 403;
}

Upvotes: 2

Related Questions