【发布时间】:2019-03-25 20:04:47
【问题描述】:
我对生产的东西不熟悉。我在数字海洋上部署了我的第一个 Django 应用程序。它正在工作。
代码更新正常,但问题在于通过 nginx 提供的静态文件。
我更新了静态文件并重新启动了 nginx 和 gunicorn,但它们没有出现在我的产品网站中。
我检查了 chrome 开发工具,它正在提供旧的静态文件。
我检查了这些更改是否存在于 prod 存储库中,但不知何故 nginx 似乎没有使用最新的静态文件。我采取的步骤
Run collectstatic command
Restart the nginx
Restart the gunicorn
静态文件的 nginx 配置
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/djangoadmin/pyapps/hkc_project;
}
这是静态设置:
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'hkc/static')
]
我还需要做些什么才能使其正常工作吗?
提前致谢
【问题讨论】:
-
你能说明你的 STATIC_URL 和 STATIC_ROOT 是如何定义的吗?
-
@JuanMiGabarron 是的,当然。
-
你完成
python manage.py collectstatic了吗?尝试使用开发工具清除缓存?
标签: django nginx production-environment