python - nginx+uwsgi+django1.5生产环境staticfiles如何配置?
ringa_lee
ringa_lee 2017-04-17 11:40:02
0
1
293

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

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

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

ringa_lee
ringa_lee

ringa_lee

reply all(1)
洪涛

Post a section of the nginx configuration I am using now:

# 代码已加码,慎重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/;
    }
}

By the way, paste the push_static part in fabfile.py:

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

local_project_root = '~/work/xxx'
online_project_root = 'deployer@example.com:~/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))
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!