How to use Django with Gunicorn

来自linux中国网wiki
跳到导航 跳到搜索

常用的WSGI容器有Gunicorn和uWSGI,但Gunicorn直接用命令启动,不需要编写配置文件,相对uWSGI要容易很多

Gunicorn 'Green Unicorn' is a Python WSGI HTTP Server for UNIX. 特点:

Gunicorn是基于prefork模式的Python wsgi应用服务器,支持 Unix like的系统

采用epoll (Linux下) 非阻塞网络I/O 模型

多种Worker类型可以选择 同步的,基于事件的(gevent tornado等),基于多线程的

高性能,比之uwsgi不相上下

配置使用非常简单

支持 Python 2.x >= 2.6 or Python 3.x >= 3.2

Installation

pip install gunicorn

on debian 
sudo apt-get install gunicorn

 cat myapp.py
def app(environ, start_response):
        data = b"Hello, World!\n"
        start_response("200 OK", [
            ("Content-Type", "text/plain"),
            ("Content-Length", str(len(data)))
        ])
        return iter([data])


gunicorn -w 4 myapp:app --bind 0.0.0.0 

run django project

if project name is  ecmdb

gunicorn  ecmdb.wsgi:application -b 0.0.0.0:8888
但是得处理一下 图片  css 什么的哦

Nginx+uwsgi+python2.7 on centos7

see also

good_Gunicorn运行与配置

django+nginx+gunicorn部署配置

nginx + gunicorn + django的简单部署

http://docs.gunicorn.org/en/latest/index.html

Nginx、Gunicorn在服务器中分别起什么作用

gunicorn 简介

gunicorn学习介绍

gunicorn 工作原理