【发布时间】:2016-03-12 16:45:49
【问题描述】:
当我通过 nginx 在 example.org(不是实际 ip)加载服务器时,内容显示正常。 但是,css和js等静态文件没有显示出来。需要做什么 更改静态文件以显示?我只是在 nginx 上做 python manage.py runserver 来检查文件是否被输入,但只有模板显示没有静态文件。
实际的静态文件夹(css/js/img)在
/opt/myenv/myproject/myproject/static
我有 /etc/nginx/sites-available/myproject
server {
listen 80;
server_name example.org; ##not actual ip
access_log /var/log/nginx/example.log;
location /static/ {
alias /opt/myenv/static/;
}
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
这就是我对 /opt/myenv/myproject/mysite/settings.py 的要求。
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
【问题讨论】: