Gunicorn搭配Django时静态资源偶发404问题求助
Gunicorn + Django 静态资源间歇性404问题
启动Gunicorn的命令:
python manage.py collectstatic --clear --noinput & gunicorn config.wsgi --bind=0.0.0.0:5000 --timeout=300 --workers=2 --threads=4 --worker-class=gthread --name=api --log-level debug --error-logfile gunicorn_error.log --access-logfile - --capture-output
请求静态CSS文件时(示例命令:curl http://0.0.0.0:5000/STATIC_DIR/CSS/FILE.css?v23423424),偶尔能正常获取文件,偶尔会返回:
Not FoundThe requested resource was not found on this server.
特殊现象:杀掉3个Gunicorn进程中的2个后,进程会快速重启,之后所有请求恢复正常。日志中未发现任何可定位问题原因的信息。有没有人遇到过类似问题?
排查建议
- 启用DEBUG日志(当前已设置
--log-level debug,可检查是否有遗漏的日志输出,或调整日志格式增加请求上下文信息) - 尝试更换不同的worker-class(比如
sync或gevent),对比是否仍会出现间歇性404问题
内容的提问来源于stack exchange,提问作者Devsss
相关产品推荐
相关产品推荐

