【发布时间】:2016-05-18 07:18:07
【问题描述】:
您好,我正在尝试在 VPS 上使用 Django 和 Nginx 提供静态数据,以使我的项目上线。我的 settings.py 包括以下内容。
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/static/
STATIC_ROOT = os.path.join(BASE_DIR, 'static', 'static')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'static', 'media')
我的项目文件夹包括:
static
----static
----static-only
----media
----templates
在 Nginx 中,我得到了以下信息:
upstream gunicorn_server {
# fail_timeout=0 means we always retry an upstream even if it failed
# to return a good HTTP response (in case the Unicorn master nukes a
# single worker for timing out).
server 127.0.0.1:9000 fail_timeout=0;
}
server {
listen 80;
server_name example.com;
keepalive_timeout 5;
client_max_body_size 4G;
access_log /home/projectuser/logs/nginx-access.log;
error_log /home/projectuser/logs/nginx-error.log;
location /static/ {
alias /venv/project/static/static;
}
location /media/ {
alias /venv/project/static/media;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://gunicorn_server;
break;
}
}
}
无论如何我都无法提供静态服务,并且管理面板 CSS 没有显示。
请尽快告知。
【问题讨论】:
标签: django ubuntu nginx gunicorn