一、基于Nginx + uwsgi + Django 框架
大致流程:
客户端 >> Nginx >> uwsgi >> Django
Nginx:反向代理,可以隐藏原有端口(如:nginx listen 8001端口,uwsgi listen 8002,我们访问8001实际上是在访问8002的内容)
uwsgi:web服务器
参考链接:https://www.cnblogs.com/yungiu/p/10387362.html
二、配置步骤
1.腾讯云服务器:centos 7 64位
2.安装python 3.6.5
(1)下载安装包:wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz ps:默认当前目录
(2)安装依赖:
(a) yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel
(b) yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
(3) 解压-编译-安装
命令:
>> ls
>> 解压tar -zxvf Python-3.6.5.tgz
>> cd - Python -3.6.5
>> 编译 ./configure --prefix=/usr/local/python3/ # 安装目录为/usr/local/python3(可以自定义安装目录)
>>设置软连接 ln -s /usr/local/python3/bin/python3 /usr/bin/python3.6
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
参考链接:https://www.cnblogs.com/yangzhaon/p/11203395.html
PS:实际过程中,pip3遇到问题,后面安装软件pip3版本过低导致无法安装其他库
报错: You are using pip version 20.0.2; however, version 20.1 is available
解决:升级pip,建立软连接
报错:read time out
解决:换下载链接
3.安装Django
python -m pip install django
4.安装uwsgi
python -m pip install uwsgi
5.配置uwsgi + django
6.配置ngnix + uwsgi +django
参考链接:
https://www.jianshu.com/p/774c92d13c7a
https://blog.csdn.net/huanbia/article/details/54630180
配合两个链接的配置流程部署,原文up写的已经很详细了,是浏览的很多链接比较好的,再次感谢~
PS:记录遇到的问题:
1.pip明明升级了,却显示仍是旧版本
2. Django 自带的splite3版本过低导致启动失败:尝试过升级,仍未解决:
借鉴一个硬核的方法:到/…/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py文件改掉版本数;
def check_sqlite_version():
# if Database.sqlite_version_info < (3, 8, 3):
if Database.sqlite_version_info < (3, 6, 3):
raise ImproperlyConfigured('SQLite 3.8.3 or later is required(found %s).' % Database.sqlite_version)
check_sqlite_version()
参考链接:http://coollsx.com/resolve-django-for-sqlite-3-8-3-or-later-is-required/
3.单独测试uwsgi 和 Nginx 是否正常工作,确保安装没有问题,再进行联接测试,基本是nignx.cof和uwgi.ini的参数修改
4.启动命令修改为:(我的nginx 是在安装文件里面启动的,不是楼上的项目文件启动的)
nginx -c /usr/local/nginx/conf/nginx.conf
uwsgi --ini /home/projects/hello2/uwsgi.ini