You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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 Found

The requested resource was not found on this server.

特殊现象:杀掉3个Gunicorn进程中的2个后,进程会快速重启,之后所有请求恢复正常。日志中未发现任何可定位问题原因的信息。有没有人遇到过类似问题?

排查建议

  • 启用DEBUG日志(当前已设置--log-level debug,可检查是否有遗漏的日志输出,或调整日志格式增加请求上下文信息)
  • 尝试更换不同的worker-class(比如sync或gevent),对比是否仍会出现间歇性404问题

内容的提问来源于stack exchange,提问作者Devsss

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 09:42:06