【问题标题】:nginx: [emerg] "if" directive is not allowed here in /etc/nginx/nginx.conf:64nginx: [emerg] "if" 指令在 /etc/nginx/nginx.conf:64 中是不允许的
【发布时间】: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 只能放在 serverlocation 块内。其他任何地方都会导致该错误。
  • 那我该怎么办?我一直在尝试一切。
  • 使用nginx -T(大写T)查看所有包含文件的完整配置,并确定哪个文件包含您网站的server块。

标签: ubuntu nginx


【解决方案1】:

Nginx 只允许将if 放在serverlocation 块中。 if 也不应该主要在 nginx.conf 中,而应该在 /etc/nginx/sites-enabled/name.conf/etc/nginx/sites-available/name.conf 上。

您也不能在 nginx.conf 中放置 serverlocation 块,因为它只会给出另一个错误。

【讨论】:

    猜你喜欢
    • 2020-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-17
    • 2016-02-08
    • 1970-01-01
    • 2021-08-30
    • 1970-01-01
    相关资源
    最近更新 更多