我使用一些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个月前开始,所以我不能去最新的日志做它的大小
不要忘记在你的gunicorn服务文件中设置编码(否则你可能会遇到奇怪的Unicode错误,看起来你正在使用上面介绍的函数遇到这个问题。)
[service]
Environment="LANG=ru_RU.UTF-8"
这可能是你的一个相关问题:UnicodeEncodeError [Python3/Gunicorn/Nginx/Django]
似乎像这样工作:
journalctl --unit=gunicorn | tail -n 300