Ubuntu部署django
本文最后更新于:星期四, 二月 3日 2022, 9:15 晚上
写在前面
又是工具人的一天
环境配置
- ubuntu16.04
- python3.7.1
- nginx
- uwsgi
python3.7.1 安装
| sudo apt-get install zlib1g-dev libbz2-dev libssl-dev libncurses5-dev libsqlite3-dev libreadline-dev tk-dev libgdbm-dev libdb-dev libpcap-dev xz-utils libexpat1-dev liblzma-dev libffi-dev libc6-dev
|
| wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz
|
| sudo mkdir -p /usr/local/python3
|
| ./configure --prefix=/usr/local/python3 --enable-optimizations make sudo make install
|
| rm -rf /usr/bin/python3 rm -rf /usr/bin/pip3
|
| #添加python3的软链接 ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3 #添加 pip3 的软链接 ln -s /usr/local/python3/bin/pip3.7 /usr/bin/pip3
|
获取项目文件
| pip3 install virtualenv # 清华源安装方式 pip3 install virtualenv -i https://pypi.python.org/simple/ python3 -m venv env # env为虚拟环境名字
|
| source env/bin/activate # 退出虚拟环境 deactivate
|
| pip install -r requirements.txt
|
uwsgi配置
| uwsgi --http :8000 --file web/wsgi.py --static-map=/static=static
|
访问localhost:8000
看能否访问
| [uwsgi] master = true processes = 1 threads = 2 chdir = /www/wwwroot/project_plane/web/ # mangge.py 目录 wsgi-file= /www/wwwroot/project_plane/web/web/wsgi.py # wsgi.py 路径 http = 0.0.0.0:8080 # 运行端口 chmod-socket = 660 vacuum = true max-requests = 1000
|
查看否有报错
如果有则可以访问 localhost:8080
到这里uwsgi就配置完成了
nginx配置
安装宝塔后新建站点
添加反向代理
到这里 就算部署完成了