django - django 承接nginx请求
2014-04-25 11:06
393 查看
# -*- coding: utf-8 -*- import os import sys import tornado.ioloop import tornado.web import tornado.wsgi import tornado.httpserver from django.core.handlers.wsgi import WSGIHandler # 设置 Django 设置模块,sets the default settings module to use _HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.append(_HERE) os.environ['DJANGO_SETTINGS_MODULE'] = "settings" def main(port): # 利用 tornado 的http server处理消息请求 wsgi_app = tornado.wsgi.WSGIContainer(WSGIHandler()) # Application 处理请求消息 tornado_app = tornado.web.Application( # FallbackHandler: A RequestHandler that wraps another HTTP server callback. # http://www.tornadoweb.org/en/stable/web.html#tornado.web.FallbackHandler [('.*', tornado.web.FallbackHandler, dict(fallback=wsgi_app)), ]) # HTTPServer is a very basic connection handler. It parses the request headers and body server = tornado.httpserver.HTTPServer(tornado_app) server.listen(port) tornado.ioloop.IOLoop.instance().start() if __name__ == '__main__': try: import setproctitle setproctitle.setproctitle('www:' + sys.argv[1]) except ImportError: pass main(int(sys.argv[1]))
基本思想:利用 tornado 的 http server,处理消息请求。
官方文档有介绍:
WSGIContainer lets you run other WSGI applications and frameworks on the Tornado HTTP server. For example, with this class you can mix Django and Tornado handlers in a single server.
详细内容,见代码注释。
相关文章推荐
- Nginx防盗链的3种方法
- 为nginx添加ngx_lua模块并进行安装测试
- nginx编译
- (总结)Nginx配置文件nginx.conf中文详解
- nginx多server日志分割脚本分享
- nginx启动,重启,关闭命令
- Nginx的特性与核心类别及配置文件和模块详解
- nginx rtmp 流媒体
- Nginx编译安装和配置详解
- virtualenv下配置nginx uwsgi Django
- nginx均衡负载的设置
- nginx rewrite arg 带问号的地址转发参数处理?Nginx重定向的参数问题
- linux+nginx+python+django环境配置
- nginx 负载均衡的五中不同配置方式
- SUSE11安装NginxMongoSybasePHP环境
- 整理:Nginx+PHP+MySQL安装过程
- 10 个 Nginx 的安全提示
- nginx的upstream模块数据转发过程及流量控制分析
- Nginx服务器的配置,使用Lua语言在MySQL数据交互
- ecstore nginx下去掉index.php入口文件