zoukankan      html  css  js  c++  java
  • ubuntu使用uwsgi+nginx部署django

    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
  • 相关阅读:
    JS中数组的排序
    JS中输入身份证号码,subString截取出生日,并判断性别
    JS中for循环输出三角形
    JS中for循环实现s=x^y。
    JS中用for实现n的阶乘
    JS实现:for循环输出1000以内水仙花数
    JS中用if..else 查询成绩
    JS——do...while循环输出斐波拉契数前20项
    JS中while循环 ,二分法,产生随机数,计算机猜几次能猜中
    2018年5月9日JAVA-servlet01
  • 原文地址:https://www.cnblogs.com/puqunzhu/p/10042645.html
Copyright © 2011-2022 走看看