一次Django站点部署纪要

公司服务器要迁移到更高的配置,所以需要升级服务器。正好之前的服务器上的系统和各种软件版本都已经过时,于是就一并升级了。在过程中还是遇到蛮多坑的。

由于Django版本升级过程复杂,还要涉及到很多代码的修改,所以这次配置还是维持了古老的1.6.5版本不变。

过程摘录如下:

tools

sudo apt-get install sysv-rc-conf
sudo apt-get install git
sudo apt-get install python-dev

Nginx

sudo vim /etc/apt/sources.list.d/nginx.list

add follow lines in /etc/apt/sources.list.d/nginx.list

deb http://nginx.org/packages/mainline/ubuntu/ trusty nginx
deb-src http://nginx.org/packages/mainline/ubuntu/ trusty nginx
wget -q -O- http://nginx.org/keys/nginx_signing.key | sudo apt-key add -
sudo apt-get update
sudo apt-get install nginx
sudo vim /etc/nginx/conf.d/proj_name.conf

/etc/nginx/conf.d/proj_name.conf

server {
    listen 80;
    server_name www.domain_name.com;
    charset utf-8;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /s/ {
        alias /srv/www/site_dir/static/;
    }

    location / {
        proxy_read_timeout      300;
        include       uwsgi_params;
        uwsgi_pass    unix:///srv/www/proj_name/proj_name.sock;
    }

    gzip            on;
    gzip_min_length 1000;
    gzip_proxied    expired no-cache no-store private auth;
    gzip_types      text/plain text/css application/x-javascript;
}

MySQL

# apt-get install software-properties-common
sudo add-apt-repository -y ppa:ondrej/mysql-5.7
sudo apt-get update
sudo apt-get install mysql-server
# then add user and restore databases

redis

sudo add-apt-repository ppa:chris-lea/redis-server
sudo apt-get update
sudo apt-get install redis-server

code

cd /srv/www/
git clone repo site_dir
# modify settings.py
# DATABASE fields
# Redis fields
"LOCATION": "redis://127.0.0.1:6379/1",

virtualenv

sudo apt-get install python-pip
pip install virtualenv

# enable virtrualenv
cd /srv/www/site_dir
virtualenv env
source /env/bin/activate

django

#env
pip install django==1.6.5

modules

# env
pip install django-redis
pip install django-robots
pip install django-crontab==0.6.0
pip install django-contrib-comments==1.6.1
pip install django-recaptcha
pip install south
pip install django-social-auth
pip install django-widget-tweaks
pip install unidecode

MySQL-Python

sudo apt-get install python-dev
sudo apt-get install libmysqlclient-dev
pip install mysql-python

PIL

sudo apt-get build-dep python-imaging
sudo apt-get install libjpeg8 libjpeg62-dev libfreetype6 libfreetype6-dev
pip install PILLOW

uWSGi

pip install uwsgi
cd /etc/uwsgi/apps-available
vi proj_name.ini

/etc/uwsgi/apps-available/proj_name.ini

[uwsgi]
project = proj_name
base = /srv/www

chdir = %(base)/%(project)
home = %(base)/%(project)/env
module = app_name.wsgi:application

master = true
processes = 20

socket = %(base)/%(project)/%(project).sock
#socket = 127.0.0.1:1234
chmod-socket = 664
#chmod-socket = 666
vacuum = true
logto = %(base)/%(project)/logs/uwsgi.log
enable-threads  = true
plugins = python
uid = www-data
gid = www-data
chown-socket = www-data
cd /etc/uwsgi/apps-enabled
ln -s ../apps-available/proj_name.ini proj_name.ini

暂无评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注