nginx: [emerg] unknown directive
程序员文章站
2022-06-13 19:30:23
...
服务器遭到一个agent包含java/1.6.0的频繁攻击,本打算按照如下的方式配置nginx来屏蔽请求
location /{
if($http_user_agent ~* "java/1.6.0"){
rewrite ^(.*)$ http://img.mp.itc.cn/upload/20160716/6362d52b6ade45cdb6e354fd9de64d4a_th.jpg redirect;
}
}
nginx重启的时候出现如下异常:
nginx: [emerg] unknown directive "if($http_user_agent" in /usr/local/nginx/conf/nginx.conf:86
原因是:
if 和 ( 缺一个空格 ,如果没有空格他把if($http_user_agent当成一个指令去执行,很显然这样是错误的。
推荐阅读
-
nginx FastCGI错误Primary script unknown解决办法
-
Nginx反向代理proxy_cache_path directive is not allowed错误解决方法
-
nginx: [warn] "log_format" directive used only on "http" level 解决方法
-
Nginx 配置问题 server directive is not allowed here in /etc/nginx/nginx.conf:69
-
由于Nginx配置文件问题导致打不开网站unknown directive的解决
-
nginx: [emerg] getpwnam("nginx") failed
-
nginx FastCGI错误Primary script unknown解决办法
-
nginx: [warn] "log_format" directive used only on "http" level 解决方法
-
nginx报错[emerg] duplicate upstream
-
nginx: [emerg] unknown directive