【发布时间】:2017-02-01 10:14:05
【问题描述】:
我正在部署一个 Django 项目,使用:
- 虚拟环境
- nginx
- 独角兽
按照本教程进行操作:https://www.digitalocean.com/community/tutorials/how-to-deploy-a-local-django-app-to-a-vps
我的配置
django 设置
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
STATIC_URL = '/static/'
/etc/nginx/sites-available/esmart2
GNU nano 2.0.9 File: /etc/nginx/sites-available/esmart2
server {
server_name 192.168.30.17;
access_log off;
location /static/ {
alias /new_esmart/esmart2/static/;
}
location / {
proxy_pass http://127.0.0.1:8001;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
}
}
跑步
(esmart_env) [root@eprssrv09 esmart2]# /new_esmart/esmart_env/bin/gunicorn --bind 192.168.30.17:8001 esmart2.wsgi:application
我的 Django 项目正在运行,但是:
Not Found: /static/admin/css/login.css
有什么建议吗?
更新 1 我认为避免了nginx设置:
删除 'sites-enabled' 文件夹中的任何引用,django 项目运行,但有关静态文件的问题仍然存在。
更新 2
如果在 Django 设置中 debug=True 我得到了
Not Found: /static/admin/css/base.css
Not Found: /static/admin/css/login.css
Not Found: /static/admin/css/base.css
【问题讨论】:
-
您阅读过静态文档吗?您的 STATIC* 设置是什么?你跑
collectstatic了吗? -
@DanielRoseman 我已经用 django 静态设置编辑了我的问题,我已经运行了 collectstatic 并且所有静态文件都在 /new_esmart/esmart2/static/
标签: django nginx static gunicorn