nginx+uwsgi+django1.5生产环境staticfiles如何配置?


nginx+uwsgi+django1.5生产环境staticfiles如何配置?

使用manage.py collectstatics 将static文件拷贝到了STATIC_ROOT目录下,urls.py中需要添加r'static/$'路径吗?还需要怎么设置?

怎么设置能让nginx直接去处理这些css js文件?

web python django nginx Linux

妹子!你好萌 10 years, 2 months ago

贴一段我现在在用的nginx配置吧:


 # 代码已加码,慎重copy
server {
    listen  80;
    access_log /var/log/nginx/project_name_access.log;
    error_log /var/log/nginx/project_name_error.log;

    location / {
        proxy_pass http://127.0.0.1:8111;
        proxy_set_header Host  $http_host;
        proxy_set_header X-Forwarded-For  $remote_addr;
    }

    location  /static/ {
        alias /www/project_root/collectstatic/;
    }
}

顺便贴一下fabfile.py里面,push_static部分:


 # 代码已加码,慎重copy
from fabric.api import local

local_project_root = '~/work/xxx'
online_project_root = '[email protected]:~/www/xxx'


def push_static():
    """Push static files to online."""
    rsync = "rsync -avz --progress %s/collectstatic/ %s/collectstatic/"

    local('python manage.py collectstatic')
    local(rsync % (local_project_root, online_project_root))

milkman answered 10 years, 2 months ago

Your Answer