ubuntu使用uwsgi+nginx部署django
16lz
2021-01-22
ls -lha
export WORKON_HOME=~/venv
source /usr/local/bin/vitualenvwrapper.sh
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
安装python3
apt-get update
sudo apt-get install python3-dev build-essential libssl-dev libffi-dev libxml2 libxml2-dev libxslt1-dev zlib1g-dev
sudo apt-get install python3
sudo apt-get install python3-pip
1.什么是服务器?
激活虚拟环境:
sudo pip3 install virtualenv
sudo pip3 install virtualenvwrapper
source bin/activate
pip3 install django==1.11.6
django-admin startproject smartkidz
python3 manage.py startapp api
关闭虚拟环境:
deactivate
pip freeze
pip freeze > req.txt
pip3 install -r req.txt
sudo apt-get install libmysqlclient-dev
pip install mysqlclient
安装数据库
sudo apt-get install mysql-server
进入数据库创建自己的账户并给分配所有的权限,并且刷新权限,在配置文件当中bind 0.0.0.0
python3 manage.py runserver
部署上线uwsgi的安装及测试
安装uwsgi
pip3 install uwsgi -i https://pypi.douban.com/simple/
测试
uwsgi --http :8000 --module GuLiEdu.wsgi
安装配置nginx
sudo apt-get install nginx
smartkidz_nginx.conf
# the upstream component nginx needs to connect to
upstream django {
# server uninx:///path/to/your/mysite/mysite.sock; # for a file socket
server 127.0.0.1:8000; # for a web port socket (we'll use this first)
}
#configuration of the server
server {
#the port your site will be served on
listen 80;
#the domain name it will serve for
server_name 47.106.224.45;
charset utf8;
#max upload size
client_max_body_size 75M;
location /static {
alias /home/smartkidz/smartkidz/static;
}
location /{
uwsgi_pass django;
include /etc/nginx/uwsgi_params;
}
}
将该配置文件加入到nginx的启动配置文件夹中
sudo cp smrtkidz_nginx.conf /etc/nginx/conf.d/
python3 manage.py collectstatic
sudo service nginx restart
ps -aux|grep nginx
# ite_uwsgi.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /home/python/smartkidz/
# Django's wsgi file
module = smartkidz.wsgi
# the virtualenv(full path)
# process-related settings
#master
master = true
process = 10
socket = 127.0.0.1:8000
vacuum = true
virtualenv = /home/venv
logto = /tmp/mylog.log
uwsgi -d -i uwsgi.ini
sudo netstat -antup
sudo kill 7358
更多相关文章
- cocos2d-3.2+python+NDK搭建游戏开发环境
- 环境变量的安装以及python cahrm的安装以及常用快捷键的使用
- ubuntu下eclipse pydev 离线 环境搭建 及相关问题解决
- 从零开始部署Django生产环境(适用:《跟老齐学Python Django实战》)
- Python 虚拟环境 windows平台 virtualenv
- Mac环境下配置python3
- Python虚拟环境包导出
- Python开发环境Wing IDE搜索工具介绍
- Python环境那点儿事(Windows篇)