1.下载与项目对应的django版本
pip3 install django==1.11.16 -i https://pypi.douban.com/simple/
2.用django内置的wsgi模块测试项目是否可以正常运行
python manage.py runserver 0.0.0.0:8080
3.下载uwsgi--此文所用版本:2.0.17.1
pip install uwsgi
4.测试uwsgi是否可以正常使用
  1>测试文件test.py

def application(env, start_response):
        start_response('200 OK',[('Content-Type', 'text/html')])
        return [b'Hello world'] # Python3

  2>测试语句
  uwsgi --http 0.0.0.0:8080 --wsgi-file test.py
  3>选做:可以直接命令测试django项目是否可以用uwsgi运行
  切换到django的项目根目录中

[root@VM_0_3_centos day18_crm]# ls
crm  day18_crm  manage.py  nohup.out  rbac  README3  script  static  templates
[root@VM_0_3_centos day18_crm]# pwd
/data/day18_crm

  注意:运行之前必须收集django项目的静态文件 --如果你的项目是每个APP下都有static文件夹的话
  python manage.py collectstatic
  uwsgi --http 0.0.0.0:8080 --file day18_crm/wsgi.py --static-map=/static=static
5.在django项目根目录中创建uwsgi.ini,将uwsgi参数写到配置文件中,后续与nginx配合
  1>文件内容如下

[uwsgi]# uwsgi +django直接用的时候web端口号
#http= :9000
#niginx将动态请求代理回此端口号
socket=0.0.0.0:8080
#项目目录
chdir= /data/day18_crm
#wsgi.py
wsgi-file=day18_crm/wsgi.py
processes=4 #进程
threads=2 #线程
stats =:9191
#服务停止的时候清除 socket环境
vacuum=true 

6.用uwsgi启动django
  1>正常启动
    uwsgi --ini uwsgi.ini
  2>后台挂起式启动
    nohup uwsgi uwsgi.ini &
7.下载安装nginx--此文所用版本:nginx version: nginx/1.12.2
  1>下载
    yum -y install nginx
  2>测试--查看xx.xx.xx.xx:80 nginx是否正常
    systemctl start nginx.service
8.nginx配置
  1>在django项目根目录创建uwsgi_params(注意文件名字不要错),改成777的权限,文件内容如下

uwsgi_param  QUERY_STRING       $query_string;
uwsgi_param  REQUEST_METHOD     $request_method;
uwsgi_param  CONTENT_TYPE       $content_type;
uwsgi_param  CONTENT_LENGTH     $content_length;

uwsgi_param  REQUEST_URI        $request_uri;
uwsgi_param  PATH_INFO          $document_uri;
uwsgi_param  DOCUMENT_ROOT      $document_root;
uwsgi_param  SERVER_PROTOCOL    $server_protocol;
uwsgi_param  REQUEST_SCHEME     $scheme;
uwsgi_param  HTTPS              $https if_not_empty;

uwsgi_param  REMOTE_ADDR        $remote_addr;
uwsgi_param  REMOTE_PORT        $remote_port;
uwsgi_param  SERVER_PORT        $server_port;
uwsgi_param  SERVER_NAME        $server_name;

  2>切换到nginx服务
    cd /etc/nginx/conf.d/
  3>创建配置文件--crm_nginx.conf

upstream django {
    # server unix:///path/to/your/mysite/mysite.sock; # for a file socket
    server 0.0.0.0:8080; # for a web port socket (we'll use this first) 与uwsgi.ini的socket ip保持一致
}

# configuration of the server
server {
    # the port your site will be served on 服务访问的时候的IP xx.xx.xx.xx:8000/crm/login
    listen      8000;
    # the domain name it will serve for
    server_name 0.0.0.0; # substitute your machine's IP address or FQDN 服务器IP
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    #location /media  {
     #   alias /path/to/your/mysite/media;  # your Django project's media files - amend as required
   # }

    location /static {
        alias /data/day18_crm/static; # your Django project's static files - amend as required 收集的静态文件目录
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;  #代理块
        include     /data/day18_crm/uwsgi_params; # the uwsgi_params file you installed 与nginx通信用的,在django的根目录中存在的文件
    }
}

  4>查看django项目根目录文件

[root@VM_0_3_centos day18_crm]# ls
crm  day18_crm  manage.py  nohup.out  rbac  README3  script  static  templates  uwsgi.ini  uwsgi_params (俩个重要的文件)

9.启动nginx
  1>启动
  systemctl start  nginx.service
  2>查看现在需要的端口是否都启动
  netstat -tunlp

tcp        0      0 0.0.0.0:9191            0.0.0.0:*               LISTEN      20406/uwsgi
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      20406/uwsgi      #动态文件交给uwsgi处理
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      12460/nginx: master
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      16787/sshd
tcp        0      0 0.0.0.0:8000            0.0.0.0:*               LISTEN      12460/nginx: master #niginx处理静态文件的端口
tcp6       0      0 :::3306                 :::*                    LISTEN      14978/mysqld
tcp6       0      0 :::80                   :::*                    LISTEN      12460/nginx: master
udp        0      0 0.0.0.0:68              0.0.0.0:*                           880/dhclient
udp        0      0 172.27.0.3:123          0.0.0.0:*                           550/ntpd
udp        0      0 127.0.0.1:123           0.0.0.0:*                           550/ntpd
udp        0      0 0.0.0.0:123             0.0.0.0:*                           550/ntpd
udp        0      0 0.0.0.0:44221           0.0.0.0:*                           22821/ntpdate
udp        0      0 0.0.0.0:59948           0.0.0.0:*                           880/dhclient
udp6       0      0 :::41081                :::*                                880/dhclient
udp6       0      0 :::123                  :::*                                550/ntpd    

  3>再收集一遍静态文件
    注意:一定要在django的settings.py中需要配置static根目录
    STATIC_ROOT =  os.path.join(BASE_DIR,'static')
    python manage.py collectstatic

django+uwsgi+nginx的部署的更多相关文章

  1. 阿里云 centos7 django + uWSGI+Nginx + python3 部署攻略

    centos7+nginx+python3+django+uwsgi配置Django 项目部署   1.租的服务器(选择centos)的话,需要在阿里云后台控制台开放几个端口,克隆一下已开放的端口,t ...

  2. Django部署,Django+uWSGI+nginx+Centos部署

    说明:系统是在windows上开发的,使用django1.11.4+python3.6.3开发,需要部署在centos6.4服务器上. 第一步:在Centos6.4上安装Python3.6.2 安装请 ...

  3. Django+uwsgi+Nginx安装部署

    安装 安装Nginx Nginx是最流行的高性能HTTP服务器. 安装pcre: wget https://sourceforge.net/projects/pcre/files/pcre/8.37/ ...

  4. django+uwsgi+nginx+sqlite3部署+screen

    note:可通过该命令查找文件未知 sudo find / -name filename 一:项目(github) ssh root@server ip         #  连接你的服务器 git ...

  5. Django+Uwsgi+Nginx项目部署文档

    一.基本环境搭建 1)查看服务器 [root@Myjumpserver ~]# cat /etc/sysconfig/selinux SELINUX=disabled SELINUXTYPE=targ ...

  6. docker简单使用+django+uwsgi+nginx项目部署

    使用docker 搭建 centos7 环境: 主机环境:windows 10专业版 一.安装docker Hub.docker.com官网下载 docker for windows 安装完成后,任务 ...

  7. centos7 nginx配置httpsCenos(6.6/7.1)下从源码安装Python+Django+uwsgi+nginx环境部署(二)

     1.yum安装nginx 下载对应当前系统版本的nginx包(package) # wget  http://nginx.org/packages/centos/7/noarch/RPMS/ngin ...

  8. CentOS7.4部署Python3+Django+uWSGI+Nginx

    CentOS7.4部署Python3+Django+uWSGI+Nginx http://www.showerlee.com/archives/2590

  9. django项目在uwsgi+nginx上部署遇到的坑

    本文来自网易云社区 作者:王超 问题背景 django框架提供了一个开发调试使用的WSGIServer, 使用这个服务器可以很方便的开发web应用.但是 正式环境下却不建议使用这个服务器, 其性能.安 ...

随机推荐

  1. Java的selenium代码随笔(8)

    Selenium截图方法一: Selenium中截图类TakeScreenshout,这个类主要是获取浏览器窗体内的内容,不包括浏览器的菜单和桌面的任务栏区域,我们用百度首页来截图,看看截图效果. F ...

  2. quotes 整站数据爬取存mongo

    安装完成scrapy后爬取部分信息已经不能满足躁动的心了,那么试试http://quotes.toscrape.com/整站数据爬取 第一部分 项目创建 1.进入到存储项目的文件夹,执行指令 scra ...

  3. Linux centos ssh

    创建m01.backup.nfs.web01.web02 m01(172.16.1.61).backup(172.16.1.41).nfs(172.16.1.31).web01(172.16.1.7) ...

  4. golang面向对象和interface接口

    一. golang面向对象介绍 1.golang也支持面向对象编程,但是和传统的面向对象编程有区别,并不是纯粹的面向对象语言.2.golang没有类(class),golang语言的结合体(struc ...

  5. Python——模块——配置模块(ConfigParser)

    一.读取 read(filename) 直接读取ini文件内容  sections() 得到所有的section,并以列表的形式返回 options(section) 得到该section的所有opt ...

  6. Oracle篇 之 数据操作

    一.DML 数据操作语言(Data Manipulation Language) 1.insert insert into student values(1,'briup1',20,'Male'); ...

  7. Leetcode 8 Two Pointers

    Two Pointers 1. 28. Implement strStr() 用 i 记录haystack偏移量,j 记录 needle 的偏移量. class Solution { public i ...

  8. 关于【jq插件开发】

    很详细,原文链接:https://www.cnblogs.com/Wayou/p/jquery_plugin_tutorial.html#commentform和https://www.cnblogs ...

  9. Django异步任务之Celery

    Celery celery 是一个用于实现异步任务的库, 在很多项目中都使用它, 它和 django 融合使用很完美. 使用 celery 可以在实现 http request请求返回 view 前做 ...

  10. cv2.matchTemplate()函数的应用,匹配图片后画出矩形

    import cv2 as cv import numpy as np """ matchTemplate(): 参数image:待搜索的图像(大图) 参数temple: ...