django+nginx+ubuntu

开发环境

git push

服务器环境

git reset --hard HEAD //忽略服务器端修改
git pull
*常用命令
sudo service nginx restart//重启nginx服务
*tips
添加静态文件jpg后,本地开发环境可正常访问,服务器端图片加载失败?解决方法:settings.py中需配置STATIC_URL和STATICFILES_DIRS,指定STATIC_ROOT路径,

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'common_static'), #主文件下静态文件
)
STATIC_ROOT = os.path.join(BASE_DIR, "static")

服务器端部署时运行python manage.py collecstatic将所有静态文件收集到STATIC_ROOT 指定的路径;
nginx配置文件中需指定静态文件路径,否则无法访问(切记路径名称static也会拼接到root指定的路径中去,请勿重复指定,导致无法找到路径。)
假设我要访问的地址是:127.0.0.1/images/tmp.jpg
静态资源地址是:/usr/local/static/images/tmp.jpg
https://www.jianshu.com/p/87954346b7bb

//root配置
//127.0.0.1/images/tmp.jpg   =   /usr/local/static/images/tmp.jpg

location /images/ {
     root  /usr/local/static/
}

//alias配置  
//127.0.0.1/images/tmp.jpg   =   /usr/local/static/images/tmp.jpg
location /images/ {
     alias  /usr/local/static/images/
}

你可能感兴趣的:(django+nginx+ubuntu)