nginx: [emerg] unknown directive

The server was frequently attacked by an agent containing java/1.6.0. I planned to configure nginx as follows to block requests

 location /{

       if($http_user_agent ~* "java/1.6.0"){

           rewrite ^(.*)$ http://img.mp.itc.cn/upload/20160716/6362d52b6ade45cdb6e354fd9de64d4a_th.jpg redirect;

       }

    }

When nginx restarts, the following exception occurs:

nginx: [emerg] unknown directive "if($http_user_agent" in /usr/local/nginx/conf/nginx.conf:86

The reason is:

    If and ( are missing a space, if there is no space, he will execute if( $http_user_agent as a command, which is obviously wrong.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326522122&siteId=291194637