首先去安装django uwsgi nginx
sudo apt-get install nginx
pip install django
pip install uwsgi
安装好后,去配置nginx的文件
server { listen 81; server_name 47.104.199.225 ; charset utf-8; client_max_body_size 75M; location /static { alias /home/appium_ui_test/static; } location / { include uwsgi_params; uwsgi_pass 127.0.0.1:9991; uwsgi_param UWSGI_PYTHON /usr/bin/python3; uwsgi_param UWSGI_CHDIR /home/appium_ui_test/; uwsgi_param UWSGI_MODULE manage; uwsgi_param UWSGI_CALLABLE application; } }
/static 这个必须配置,不然一些静态文件会找不到
重启nginx服务
sudo /etc/init.d/nginx restart
然后去配置uwsgi
[uwsgi] chdir=/home/appium_ui_test/ wsgi-file = apptest.wsgi.py # 指定项目的application module=apptest.wsgi:application socket = 127.0.0.1:9991 master = true //主进程 vhost = true //多站模式 no-site = true //多站模式时不设置入口模块和文件 workers = 2 //子进程数 reload-mercy = 10 vacuum = true //退出、重启时清理文件 max-requests = 1000 limit-as = 512 plugins = python3 buffer-size = 30000 pythonpath =/usr/local/lib/python3.5/dist-packages/
再启动你的uwsgi
sudo /usr/bin/uwsgi --ini django_uwsgi.ini
有几次报错说找不到django可是自己python环境有。
其实增加一个pythonpath就可以解决
增加supervisor管理,当chrash了,可以自动重启 安装后/etc/supervisor/conf.d/ 配置一个文件,如下 简单配置 command=uwsgi /home/flask/flask_blog-python3/helloflask_uwsgi.ini autostart=ture autorestart=true stdout_logfile=/home/flask/flask_blog-python3/uwsgi_supervisor.log user=root 配置后启动 service supervisor start 终止服务 service supervisor stop
至此,我们就部署好我们的django,可以访问了。