在阿里云上部署django前,可以首先在本机上按照完全一样的设置部署django,这样方便调试。我在阿里云ecs上使用的系统是ubuntu,因此,在本机调试时,也使用ubuntu系统。
1. 安装nginx
ubuntu下输入下列语句安装nginx:
sudo apt-get install python-dev nginx
如果使用python3,则需要输入:
sudo apt-get install python3-dev nginx
2. 安装supervisor
supervisor时一个进程管理工具,用来管理gunicorn
sudo pip install supervisor
备注:
如果pip尚未安装,在ubuntu16.04下输入以下命令安装pip
wget https://bootstrap.pypa.io/get-pip.py --no-check-certificate
sudo python get-pip.py
3. 使用gunicorn进行部署
可选择的部署工具有两种,gunicorn和uwsgi,gunicorn为纯python实现的包;uwsgi为纯C语言实现的包。我选择了gunicorn包。
sudo pip install gunicorn