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. Echarts学习之路2(基本配置项)

    title:标题组件,包含主标题和副标题. title:{ text:"",//主标题 link:"",//主标题文本超链接 target:"&quo ...

  2. SpringMVC实现文件下载时,请求路径中的扩展名被省略

    问题描述 问题是这样的,我写了一个DownloadController,用来处理下载请求,预期效果如下: 客户端浏览器在访问URL -->   http://localhost:8080/ssm ...

  3. js中对象引用出现的问题

    先看一个特别不符合直觉的代码 <script type="text/javascript"> var a = [1,2,3,4]; var b = [1,2,3,4]; ...

  4. Base 64 & decodeURIComponent

    Base 64 & decodeURIComponent js btoa() & atob() let obj = [{"key":"q",&q ...

  5. 为什么qt成为c++界面编程的第一选择

    为什么qt成为c++界面编程的第一选择 一.前言 为什么现在QT越来越成为界面编程的第一选择,笔者从事qt界面编程已经有接近8年,在这之前我做C++界面都是基于MFC,也做过5年左右.当时为什么会从M ...

  6. StringBuilder的常用方法

    转自:https://www.cnblogs.com/jack-Leo/p/6684447.html 在程序开发过程中,我们常常碰到字符串连接的情况,方便和直接的方式是通过"+"符 ...

  7. LODOP获取打印机状态码和状态码含义测试

    由于打印机千差万别,打印机执行的标准也不一样,LODOP获取的打印状态码也可能不同,安装了个打印机驱动实际测试一下,测试的打印机驱动是Brother Color Type3 Class Driver. ...

  8. 网络知识之http请求

    使用http超文本传输协议来访问web服务器 它定义了客户端和服务器之间交互的信息内容和步骤. 客户端解析url后发送请求消息---->服务器(解析请求消息,完成工作,包装结果为响应消息)--- ...

  9. sql 根据身份证号码计算年龄

    ,), GETDATE()) / 365.25) from ConstructionInfo

  10. 差分约束 HDU - 1384 HDU - 3592 HDU - 1531 HDU - 3666

    Intervals Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...