【发布时间】:2022-04-16 06:07:44
【问题描述】:
所以我试图阻止某些网络浏览器(不是你需要知道的),每个人都说要添加 if ($http_user_agent ~* (Chrome) ) { 返回403; }
我做了所有这些,当我运行 nginx -t 时,它说: nginx: [emerg] "if" directive is not allowed here in /etc/nginx/nginx.conf:64
你们知道为什么吗?
【问题讨论】:
-
if只能放在server或location块内。其他任何地方都会导致该错误。 -
那我该怎么办?我一直在尝试一切。
-
使用
nginx -T(大写T)查看所有包含文件的完整配置,并确定哪个文件包含您网站的server块。