1.升级服务器,打上ubuntu 12的所有安全补丁
apt-get update apt-get upgrade
2.安装必要软件
apt-get install git mysql-server python-mysqldb python-pip nginx supervisor
3.在花屏界面设置mysql的root用户密码,直接输入输两次,也可以留空直接回车两次
4.安装django
pip install django -i http://pypi.douban.com/simple
5.创建数据库
CREATE DATABASE `数据库名称` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
6.进入网站的manage.py文件目录进行数据库同步
python manage.py syncdb
----------------配置python自动启动环境(相当于执行命令python manage.py runserver)----------------
7.安装python的运行环境
gunicorn pip install gunicorn
8.修改gunicorn配置
vim /etc/supervisor/conf.d/gunicorn.conf
将下面内容加入gunicorn.conf,之后按Esc再按:wq保存
[program:gunicorn] command = gunicorn ehivip_website.wsgi:application directory = /var/www/网站目录 autostart = true autorestart = true
9.重启服务让配置生效
supervisorctl reload
10.启动supervisord进程管理
supervisord
11.查看服务状态
supervisorctl status
----------------配置nginx,将本地端口映射到80----------------
12.修改nginx配置
vim /etc/nginx/sites-available/default
将下面内容加入配置
server {
root /var/www;
server_name localhost;
location /static {
root /var/www/网站目录/website;
}
location / {
proxy_pass http://127.0.0.1:8000;
}
}
13.重启nginx
service nginx restart
14.如果python代码有改启则重启
supervisorctl restart all