conda 环境不必多说: conda(或source)  activate  test 进入test虚拟环境

接下来安装uwsgi:

  pip install uwsgi 在conda环境下大概率安装不成功,可以使用一下命令代替:

    conda install -c conda-forge uwsgi

  运行uwsgi 有可能碰到 libiconv.so 动态库找不到的问题,同样可以用conda安装

    conda install -c conda-forge libiconv

uwsgi安装好后,需要在django项目根目录下建立一个名为uwsgi.ini的文件,在里面配置好uwsgi:

  

  1. [uwsgi]
  2. socket=127.0.0.1:8000 # 指定项目执行的端口号,用nginx的时候就要配socket
    pythonpath=/home/admin/test/ # 指定项目所在位置,在使用conda虚拟环境时必须要有这一条
    chdir=/home/admin/test/                  # 指定项目的目录
    wsgi-file=test/wsgi.py # 项目上wsgi.py所在的位置,与settings目录相同
    processes=1                          # 开启的进程数量
    threads=2
    master=True # master :允许主线程存在(true)
    pidfile=uwsgi.pid
    daemonize=uwsgi.log # 日志,uwsgi无法启动时来这查看错误日志

uwsgi配置好后,要启动uwsgi, 启动命令:

  uwsgi --ini uwsgi.ini          # 启动uwsgi, 一定要在django实际使用的conda环境下,否则会报错

  uwsgi --stop uwsgi.pid      # 停止uwsgi

  uwsgi --reload uwsgi.pid   #  重启uwsgi

uwsgi配置好后,要配置nginx:

  首先安装nginx, 运行命令      sudo apt install nginx

  nginx 命令:

    sudo service nginx start    启动

    sudo service nginx stop   停止

    sudo service nginx restart  重启nginx

    sudo nginx -s reload 重载配置文件

    sudo nginx -s quit 优雅的停止nginx

    sudo nginx -s term 停止nginx

    sudo nginx -s reopen 打开一份新的日志

  配置nginx:

    在/etc/nginx/site-available下新建文件test.conf:    server {

  1. listen ; #nginx监听的端口
  2. charset utf-;
  3. client_max_body_size 75M;
  4. location / {
  5.   uwsgi_pass 127.0.0.1:; # 与uwsgi中配置的相一致
  6.   include /etc/nginx/uwsgi_params;
           proxy_set_header Host $host;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  1. }

      location /static/ {   # 如果用到静态文件
        alias /home/test/test/static/;
      }

}

    然后要建立软连接:

      sudo ln -s /etc/nginx/site-available/test.conf /etc/nginx/site-enabled/test.conf

  最后用 sudo nginx -s reload 命令启动重载配置文件即可

最后, 如果需要配置负载均衡:

  1. // http模块中配置upstream
  2. upstream test {
  3. server 127.0.0.1:8002 weight=2;
  4. server 127.0.0.1:8003 weight=1;
  5. }
  6.  
  7. // 将server模块中的location替换为如下
  8. location / {
  9. proxy_pass http://test;
  10. }

uwsgi+anaconda+nginx部署django项目(ubuntu下)的更多相关文章

  1. gunicorn+anaconda+nginx部署django项目(ubuntu)

    首先进入conda 虚拟环境: source activate test 安装gunicorn: pip install gunicorn 运行gunicorn gunicorn -w 2 -b 12 ...

  2. 使用uWSGI+nginx部署Django项目

    最近使用django写了一些项目,不过部署到服务器上碰到一些问题,还有静态文件什么的一堆问题,这里总结一下碰到的问题和解决方案,总体思路是按照官方文档走的. 原文地址:http://uwsgi-doc ...

  3. ubuntu18+uwsgi+nginx部署django项目

    更新系统软件源 sudo apt-get update pip3安装 sudo apt install python3-pip 安装virtualenvwrapper pip3 install vir ...

  4. uwsgi+nginx部署django项目

    1. 概念解析(wsgi协议,uwsgi协议,uWSGI) 参考:https://www.cnblogs.com/wspblog/p/8575101.html 1.1 现实世界的web请求: 1.2  ...

  5. Ubuntu+Django+uWSGI+Nginx部署Django项目

    安装uWSGI,pip依据自己要使用的python版本自行选择,python2.x版本使用pip进行安装,python3.x版本使用pip3进行安装 pip install uwsgi 配置uWSGI ...

  6. Nginx+uWSGI或fastcgi部署Django项目

    nginx+uWSGI ubuntu下先安装下C编译器和Python环境: sudo apt-get install build-essential python-dev 使用pip安装uWSGI: ...

  7. uwsgi加nginx部署django restframework前后端分离项目

    一.uwsgi和nginx简介 1.uwsgi(摘抄于百度百科): uWSGI是一个Web服务器,它实现了WSGI协议.uwsgi.http等协议.Nginx中HttpUwsgiModule的作用是与 ...

  8. 阿里云轻量级服务器和NGINX部署Django项目

    部署条件: 1.一台阿里云服务器(本人的是CentOS系统的服务器) 2.已经构建好的项目 3.服务器上安装并配置Nginx 首先第一步:在服务器上安装并配置Nginx 进入服务器 $ ssh roo ...

  9. 关于Nginx部署Django项目的资料收集

    参考:https://www.cnblogs.com/chenice/p/6921727.html 参考:https://blog.csdn.net/fengzq15/article/details/ ...

随机推荐

  1. Linux学习之路(三)Shell脚本初探

    本文参考链接:http://www.runoob.com/linux/linux-shell.html 基本说明 Shell脚本(shell script)是一种为shell编写的脚本程序.其中she ...

  2. com.netflix.zuul.exception.ZuulException: Hystrix Readed time out

    通过API网关路由来访问用户服务,zuul默认路由规则 :http://zuul的Host地址:zuul端口/要调用的服务名/服务方法地址 浏览器中打开http://127.0.0.1:8000/wa ...

  3. 03-三层交换机的OSPF实验

    三层交换机的OSPF实验 1.OSPF介绍 开放式最短路径优先(英语:Open Shortest Path First,缩写为 OSPF)是对链路状态路由协议的一种实现,隶属内部网关协议(IGP),故 ...

  4. scala的多种集合的使用(8)之队列和栈的操作方法

    1.使用队列 队列是一种那个先进先出的队列.1)创建一个队列. scala> import scala.collection.mutable.Queue import scala.collect ...

  5. 基于配置文件的方式配置AOP

    之前说的都是通过注释的方式配置,接下来说说如何使用配置文件配置AOP 还是原来的代码,去掉所有注释,接下来配置最基本的几个bean. 然后使用<aop:config>标签进行配置,然后配切 ...

  6. TCP/IP协议、UDP协议、 Http协议

    开放式系统互联通信参考模型(Open System Interconnection Reference Model,缩写为 OSI),简称为OSI模型(OSI model),一种概念模型,由国际标准化 ...

  7. 关于Eclipse使用Git基础篇

    一:Git的下载与安装与基本使用 1.打开eclipse->help->Eclipse Markplace->search->fiind输入Egit 你会看到如下截图(我的为已 ...

  8. String,StringBuffer与StringBuilder的区别?? 缓存

    转: String 字符串常量StringBuffer 字符串变量(线程安全)StringBuilder 字符串变量(非线程安全) 简要的说, String 类型和 StringBuffer 类型的主 ...

  9. CentOS 7 安装Git

    服务器端 1.先从yum安装git yum –y install git 2.在需要的位置创建一个裸仓库(最后以.git结尾) cd /usr/local mkdir git cd git git i ...

  10. cocos 常用组件

    前面的话 本文将详细介绍 cocos 中的常用组件 Sprite [概述] Sprite(精灵)是 2D 游戏中最常见的显示图像的方式,在节点上添加 Sprite 组件,就可以在场景中显示项目资源中的 ...