一 后端上线
1.1 购买云服务器

1.2 安装python3.9
- python2.7.5 pip
- python3.6.8 pip3
-咱们项目开发,在3.9上开发的,需要使用3.9的解释器来运行
pip pip pip
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel psmisc libffi-devel zlib* libffi-devel -y
cd ~
wget https://registry.npmmirror.com/-/binary/python/3.9.10/Python-3.9.10.tgz
tar -xf Python-3.9.10.tgz
cd Python-3.9.10
./configure --prefix=/usr/local/python39
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel psmisc libffi-devel zlib* libffi-devel -y
make && make install
ln -s /usr/local/python39/bin/python3 /usr/bin/python3.9
ln -s /usr/local/python39/bin/pip3 /usr/bin/pip3.9
python 2.x pip
python3 3.6 pip3
python3.9 3.9 pip3.9
rm -rf Python-3.9.10
rm -rf Python-3.9.10.tar.xz
1.3 安装nginx
- 做请求转发 (前端来了个请求---》打在了80端口上---》转到本地8888端口,或者其他机器的某个端口)
- 静态资源代理 前端项目直接放在服务器上某个位置----》请求来了,使用nginx拿到访问的内容,直接返回
- 负载均衡 假设来了1000个请求--》打在nginx上,nginx性能很高,能顶住---》只转发到某个django项目,可能顶不住---》集群化的不是3台django---》均匀的打在3台机器上
cd ~
wget http://nginx.org/download/nginx-1.24.0.tar.gz
tar -xf nginx-1.24.0.tar.gz
cd nginx-1.24.0
./configure --prefix=/usr/local/nginx --with-http_ssl_module
make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
cd ~
rm -rf nginx-1.13.7
rm -rf nginx-1.13.7.tar.xz
nginx
服务器绑定的域名 或 ip:80
/usr/local/nginx/html
ps aux | grep nginx
关闭:nginx -s stop
启动: nginx
1.4 安装mysql 5.7
cd ~
wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum install mysql-community-server --nogpgcheck -y
systemctl start mysqld
systemctl status mysqld
grep "password" /var/log/mysqld.log
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Lqz12345?';
grant all privileges on *.* to 'root'@'%' identified by 'Lqz12345?';
如果还连不上,就是mysql 3306的安全组没开---》防火墙端口没开
连接成功
yum install python3-devel -y
yum install mysql-devel --nogpgcheck -y
pip3.9 install mysqlclient
pip3.9 install urllib3==1.26.15
pip3.9 install chardet
mkdir static
STATIC_ROOT = '/root/smart_backend/static/'
1.5 编写uwsig配置文件
<uwsgi>
<socket>127.0.0.1:8080</socket>
<chdir>/root/smart_backend/</chdir>
<module>smart_backend.wsgi</module>
<processes>4</processes>
<daemonize>uwsgi.log</daemonize>
</uwsgi>
pip3.9 install uwsgi
ln -s /usr/local/python39/bin/uwsgi /usr/bin/uwsgi
uwsgi -x smart.xml
ps aux |grep uwsgi
pkill -9 uwsgi
1.6 上传项目
DEBUG = False
ALLOWED_HOSTS = ['*']
BACKEND_URL='http://127.0.0.1:8000'
pip install pipreqs
pipreqs ./ --encoding=utf-8
baidu_aip==4.16.13
Django==3.2.22
djangorestframework==3.14.0
djangorestframework_simplejwt==5.3.1
Faker==25.0.1
pypinyin==0.51.0
SpeechRecognition==3.10.3
tencentcloud_sdk_python==3.0.1115
mysqlclient
yum install lrzsz unzip -y
rz
yum install python3-devel -y
yum install mysql-devel --nogpgcheck -y
pip install mysqlclient
pip install urllib3==1.26.15
1.7 nginx 配置(http访问)
cd /usr/local/nginx/conf
vi nginx.conf
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
server {
listen 8000;
server_name 127.0.0.1;
charset utf-8;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8080;
uwsgi_param UWSGI_SCRIPT smart_backend.wsgi;
uwsgi_param UWSGI_CHDIR /root/smart_backend/;
}
}
location /static {
alias /home/static;
}
}
nginx -s reload
1.7.1 安全组 配置
安全组-云服务器
1.8 配置admin访问
-静态资源就是在从服务器把文件,图片,js,css,直接返回
-如果静态资源也走uwsgi,会影响uwsgi的性能
10 2 个动态接口 8个 拿静态资源
usgi只负责处理这两个动态接口
静态资源不管---》自行处理
-动态请求给uwsgi---》让它处理---》uwsgi资源宝贵,尽量少用
动态请求地址: /api/v1....
-静态请求,使用nginx,直接处理---》nginx来讲,最擅长处理静态资源
静态资源地址: /static/...
-simpleui
-drf
-都在自己app中,我们需要把他们单独收集到某个位置
-后期如果部署前后端混合项目必须要做动静分离,收集静态文件
STATIC_ROOT = '/home/smart/static/'
mkdir /home/smart/static
python manage_pro.py collectstatic
http://106.14.156.208:8000/static/admin/simpleui-x/img/logo.png
server {
location /static {
alias /home/static;
}
}
nginx -s reload
1.9 阿里云证书
https://yundun.console.aliyun.com/?spm=5176.12818093_47.top-nav.23.57ea16d02gIoxM&p=cas


1.9.1 配置https访问
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
client_max_body_size 20M;
server {
listen 443 ssl;
ssl_certificate /usr/local/nginx/cert/liuqingzheng.top.pem;
ssl_certificate_key /usr/local/nginx/cert/liuqingzheng.top.key;
server_name liuqingzheng.top;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8080;
uwsgi_param UWSGI_SCRIPT smart_backend.wsgi;
uwsgi_param UWSGI_CHDIR /root/smart_backend/;
}
location /static {
alias /home/static;
}
}
}
1.10 购买域名-备案-配置域名解析
https://dc.console.aliyun.com/next/index?spm=5176.12818093_47.top-nav.40.3be916d0be3QME
二 小程序上线
https://mp.weixin.qq.com/wxamp/home/guide?lang=zh_CN&token=1879741752
const rootUrl = 'https://www.liuqingzheng.top/smart'


