【问题标题】:How to turn off logging for favicon and robots in nginx for flask (python) apps如何在 nginx 中为烧瓶(python)应用程序关闭网站图标和机器人的日志记录
【发布时间】:2016-08-05 20:19:11
【问题描述】:

我正在尝试找到一种方法来关闭我的 NGINX 网络服务器中 favicon.ico 和 robots.txt 的日志记录,该服务器通过以下方式为 Flask (Python) 应用程序提供动力uWSGI

所以,我的 nginx 配置的第一部分是:

location / {
    try_files $uri @app;
}

location @app {
    include uwsgi_params;
    uwsgi_pass unix:/srv/www/uwsgi.sock;
}

现在,当我添加时(在上面显示的代码块上方)

location = /favicon.ico {
    access_log off;
    log_not_found off;
}

location = /robots.txt {
    access_log off;
    log_not_found off;
}

当我访问这些 URI 时,我得到 404 not found 错误。现在,当我删除 location = /... 中的 = 符号时,URI 确实有效,并且我看到了 favicon 和 robots 文件。但由于某种原因,它仍然会访问这些请求的日志。

这里似乎发生了什么?

【问题讨论】:

    标签: python nginx flask uwsgi


    【解决方案1】:

    location 部分没有合并,试试:

    location = /favicon.ico {
        access_log off;
        log_not_found off;
        try_files $uri @app;
    }
    
    location = /robots.txt {
        access_log off;
        log_not_found off;
        try_files $uri @app;
    }
    

    【讨论】:

      猜你喜欢
      • 2020-09-18
      • 1970-01-01
      • 1970-01-01
      • 2021-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-25
      相关资源
      最近更新 更多