sudo apt-get install nginx
sudo apt install python3
sudo apt install python3-pip
使用 sudo pip3 install 安装 下面环境
pip3 install
uwsgi
Django
django-cors-headers # 跨域
mysqlclient # 连接MySQL
wechatpy[cryptography] #微信公众平台SDK
xlrd # 表格插件
然后在项目文件夹根目录执行下面命令,然后就可以在项目根目录下面找到后端的样式资源(static文件夹下)了
python3 manage.py collectstatic
2.环境配置
cd /etc/nginx/sites-enabled/
创建一个配置文件,如:demo,里面的内容如下,当前示例配置文件是前后端分离(Vue和Django):
server {
listen 80;
listen [::]:80;
server_name demo.zhuchenglin.cn;
# 后端Django的样式
location /static/admin/ {
expires 30d;
autoindex on;
add_header Cache-Control private;
alias /var/www/html/demo/back/static/admin/;
}
# 前端样式
location /static/ {
expires 30d;
autoindex on;
add_header Cache-Control private;
alias /var/www/html/demo/front/dist/static/;
}
# 前端找到Vue的index.html
location /front/ {
alias /var/www/html/demo/front/dist/;
index index.html index.htm;
}
# 后端处理请求
location /{
include uwsgi_params;
uwsgi_pass 127.0.0.1:9000;
uwsgi_send_timeout 600;
uwsgi_connect_timeout 600;
uwsgi_read_timeout 1000;
}
}
sudo /usr/sbin/nginx -t #检测配置文件是否有问题 sudo /usr/sbin/nginx -s stop # 快速关闭 sudo /usr/sbin/nginx -s quit # 从容关闭 sudo /usr/sbin/nginx -s reload sudo /usr/sbin/nginx -s restart
这样就可以通过域名来访问Django项目了。
注:本文操作在ubuntu系统上进行的,在其他Linux系统上安装软件的命令可能不一样(比如Centos用yum)
如需转载请注明出处:https://cloud.tencent.com/developer/article/1421776