【发布时间】:2014-05-25 00:49:18
【问题描述】:
我正在尝试将我的 django 应用程序部署到我的 VPS。所以我遵循了几个教程,唯一的问题是我无法显示我的静态文件。因此,您可以在下面找到我在 VPS 上的文件结构。
- 虚拟环境:/opt/myapps/
- Django 项目:/opt/myapps/uniprogress/
- 静态文件:/opt/myapps/uniprogress/static/
Nginx 配置:/etc/nginx/sites-available/uniprogress
server {
server_name 188.xxx.xxx.93;
access_log off;
location /static/ {
alias /opt/myapps/uniprogress/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"';
}
}
最后在我的 django settings.py 中:
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Template Dirs
TEMPLATE_DIRS = (
os.path.join(SETTINGS_PATH, 'templates'),
)
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/
STATIC_ROOT = '/opt/myapps/uniprogress/static/'
STATIC_URL = '/static/'
我也使用了:python manage.py collectstatic,但我的静态文件仍然不会显示。
更新 我使用的教程可以在Digital Ocean找到。
我仔细检查了文件是否存在于服务器上。
我还可以访问静态文件,例如:http://188.xxx.xxx.93/static/css/bootstrap.css。
但是在我的源代码http://188.xxx.xxx.93:8001/ 中,它使用端口链接静态文件。
这意味着:<link href="/static/css/bootstrap.css" rel="stylesheet">
所以它尝试在http://188.xxx.xxx.93:8001/static/bootstrap.css 找到 bootstrap.css,但该文件不存在(必须删除帖子才能使其正常工作)。
【问题讨论】:
标签: django nginx static vps gunicorn