部署文档
依赖安装
这里我们安装一些必须的依赖,请在ubuntu和debian上执行下列命令。
sudo apt-get install python3
sudo apt-get install python3-pip
sudo apt-get install nginx
sudo apt-get install git
sudo apt-get install python3-dev
apt-get install build-essential
sudo pip3 install django
sudo pip3 install djangorestframework
sudo pip3 install dwebsocket
sudo pip3 install uwsgi
部署前端文件
前端文件需要使用node.js来编译 请上node.js官方网站获取安装方法
之后将前端文件clone到本地
git clone git@github.com:EasyMealOrder/webOrder.git
git clone git@github.com:EasyMealOrder/CookEnd.git
生成点餐端:
cd webOrder
npm install
npm run build
生成厨师端:
cd CookEnd
npm install
npm run build
这两个目录中都会生成dist文件夹,里面放的就是编译好的静态文件。
后端配置
git clone git@github.com:EasyMealOrder/backEnd.git
cd backEnd
cd emo
python3 manage.py collectstatic
上述命令执行完后,backEnd/emo目录下会有collect_static目录,这是django自身的静态文件
在backEnd/emo/emo目录下存在settings.py文件,打开后最后一个设置项 WX_API_SERVER是微信登陆api服务器,本后端程序还设置了一个模拟微信登陆的功能 将这个参数设置为以下可使用:
WX_API_SERVER='http://127.0.0.1:8000/'
数据库默认使用sqlite3,如果要切换为其他数据库,请参考django的官方文档
修改settings.py
然后执行
python3 manage.py makemigrations
python3 manage.py migrate
之后配置uwsgi:
在/etc/建立uwsgi.ini文件
[uwsgi]
socket=127.0.0.1:8080
#以下填写django项目目录,具体的情况可能会有变化
chdir=/home/ubuntu/EasyOrderMeal/backEnd/emo/
#以下如果您知道是什么意思可以改动
wsgi-file=emo/wsgi.py
processes=4
threads=2
master=True
pidfile=uwsgi.pid
daemonize=uswgi.log
运行uwsgi:
uwsgi --ini /etc/uwsgi.ini
nginx配置: 注意,ngin可能配置文件位置会不同,下面是ubuntu默认的位置
cd /etc/nginx/
vim nginx.conf
在http项大括号下添加如下:
#链接uwsgi
upstream django_uwsgi{
server 127.0.0.1:8080;
}
upstream django_server {
server 127.0.0.1:8000;
keepalive 2000;
}
依然是在http项大括号下:
server {
listen 8000;
server_name localhost 0.0.0.0;
index index.html;
charset utf-8;
location / {
include /etc/nginx/uwsgi_params;
uwsgi_pass django_uwsgi;
}
location /static/ {
#注意,以下填写上面django生成的collect_static文件夹位置
alias /home/ubuntu/EasyOrderMeal/backEnd/emo/collect_static/;
}
}
server {
listen 80;
#以下填写您的ip和域名,空格隔开
server_name localhost emo.com;
charset utf-8;
index index.html;
location ^~ /cook/ {
alias /etc/CookEnd-master/dist/;
index index.html index.htm;
try_files $uri $uri/ /cook/index.html;
}
location ^~ /cloud/ {
alias /etc/WebOrder-master/dist/;
index index.html index.htm;
try_files $uri $uri/ /cloud/index.html;
#root html;
#proxy_pass http://localhost:8080;
}
location /api/ {
proxy_pass http://django_server/;
proxy_set_header Host $host:$server_port;
}
location / {
proxy_pass http://django_server/;
proxy_set_header Host $host:$server_port;
}
}
完成,重启nginx
nginx -s reload
总结下上面做的事情:让uwsgi把django跑在8080端口,让nginx把内容显示在8000端口,之后反向代理到80端口。
善后
你想要登入后台并更改东西,需要一个超级账号:
进入backEnd/emo目录:
python3 manage.py createsuperuser usernamexxxx
命令行会让你输入密码,之后你就拥有一个用户名为usernamexxx的超级账号可以进入后台了!
如果你想要使用/static/这个目录,请在上述django中collect_static加入文件