【问题标题】:Django Gunicorn where logs are stored存储日志的 Django Gunicorn
【发布时间】:2019-02-11 12:58:36
【问题描述】:

我已经使用 tutorial 部署了我的应用程序

我使用 nginx+gunicorn(我也使用 systemd)

现在在我的dev server 上一切正常 但是在生产中它失败了 Internal Server Error 当我尝试下载文件时

如何以及在哪里可以找到 gunicorn 日志?(我使用 ubuntu)

另外,这是一段会导致错误以防万一的代码:

def download_xlsx(request):
    user = request.user
    file_name = request.GET['file_name']
    file_path='main_app/static/xlsx/' + str(user.id) + '/' + file_name
    disposition= 'attachment; filename="' +smart_str(file_name) + '"'
    disposition=disposition.encode('utf-8')
    if os.path.exists(file_path):
        with open(file_path, 'rb') as fh:
            response = HttpResponse(fh.read(), content_type="application/vnd.ms-excel")
            response['Content-Disposition'] = disposition
            return response
    return projects.to_utf8_json_response('not found')

UPD:我尝试运行sudo journalctl -u gunicorn

但是我得到了一个从 2 个月前开始的大文件,所以我无法查看最新的日志,因为它的大小

【问题讨论】:

    标签: django python-3.x gunicorn


    【解决方案1】:

    似乎是这样工作的:

    journalctl --unit=gunicorn | tail -n 300
    

    【讨论】:

      【解决方案2】:

      不要忘记在您的 gunicorn 服务文件中设置编码(否则您可能会遇到奇怪的 Unicode 错误,而且您似乎在使用上述功能时遇到了这个问题。)

      [service]
      Environment="LANG=ru_RU.UTF-8"
      

      这可能与您的问题相关: UnicodeEncodeError [Python3/Gunicorn/Nginx/Django]

      【讨论】:

      • 我看了一下你用的图里亚尔。在 [Service] 部分的文件 /etc/systemd/system/gunicorn.service 中添加这一行 Environment="LANG=en_US.UTF-8" 应该可以完成这项工作
      • 没有帮助(((我使用的不是英文而是俄文字符是问题吗?
      • 是的,完全通过“LANG=ru_RU.UTF-8”代替(还要确保在您的服务器上安装了此语言环境)
      猜你喜欢
      • 1970-01-01
      • 2016-05-17
      • 1970-01-01
      • 1970-01-01
      • 2016-11-03
      • 2014-03-31
      • 1970-01-01
      • 1970-01-01
      • 2018-05-21
      相关资源
      最近更新 更多