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

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

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

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

ringa_lee
ringa_lee

ringa_lee

Antworte allen(1)
洪涛

贴一段我现在在用的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 = '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))
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!