【问题标题】:Correctly serving manifest.json via Django's gunicorn通过 Django 的 gunicorn 正确地提供 manifest.json
【发布时间】:2020-03-03 23:07:15
【问题描述】:

我有一个 Django Web 应用程序,它利用带有 gunicorn 应用程序服务器(上游)的 nginx 反向代理。

我的 nginx 日志充满了如下错误:2020/03/03 22:51:57 [error] 9605#9605: *162393 upstream sent too big header while reading response header from upstream, client: 168.155.46.104, server: example.com, request: "GET /static/img/favicons/manifest.json HTTP/2.0", upstream: "http://unix:/home/ubuntu/app/myproj/gunicorn.sock:/static/img/favicons/manifest.json", host: "example.com", referrer: "https://example.com/signup/create-pass/new/6d756265726e2d3131/18/"

我假设 gunicorn 无法为 manifest.json 提供服务。

这不应该发生。我创建了manifest.json 并将其放置在相关位置。在https://realfavicongenerator.net/ 使用网站图标检查器会显示此错误: The Web App Manifest at https://example/com/static/img/favicons/site.webmanifest cannot be downloaded。如果我直接在浏览器中点击该网址,我最终会看到 502 Bad Gateway 错误。

我该如何解决这个问题?

【问题讨论】:

    标签: django nginx gunicorn


    【解决方案1】:

    我发现了错误。

    放置在我项目中/static/ 文件夹中的文件应该直接通过 nginx 提供。但是有问题的 json 文件并未以允许 Web 服务器提供服务的方式包含在 nginx conf 中。

    一旦我解决了这个问题(见下文),清单文件就直接由 nginx 提供(并且 gunicorn 从未进入循环)。问题解决了!


    这是我添加到 nginx 的虚拟主机文件以解决问题:注意这包括 json 扩展名:

    location ~* \.(?:ico|css|js|gif|jpg|jpeg|png|svg|woff|ttf|eot|json)$ {
    
        root /home/ubuntu/app/my_proj;
        expires 120d;
        access_log off;
        error_log off;
    }
    

    【讨论】:

      猜你喜欢
      • 2017-03-01
      • 2011-02-02
      • 2023-04-01
      • 2019-10-26
      • 2015-11-30
      • 1970-01-01
      • 2013-06-27
      • 2017-05-31
      • 1970-01-01
      相关资源
      最近更新 更多