tornado + nginx + supervisord 环境部署

学习tornado有一周多了,自己按着demo中的例子手动搬代码,收获还是有的,加深了理解。demo: http://demo.pythoner.com/itt2zh/ch8.html

大概明白了它怎么工作后,开始部署一个线上环境跑跑。

nginx: 分配客户端请求给upstream组中列出的Tornado实例。其中静态目录的文件由nginx直接提供。

supervisord: tornado进程管理。

tornado: 功能实现。

关于nginx

在/etc/nginx/site-enable/default中 新增:

upstream frontends{
    server 127.0.0.1:8880;
}

server {
    listen 8000;

    location / {
        proxy_read_timeout 1800;
        proxy_pass_header Server;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_pass http://frontends;
    }
}

关于supervisord

确认是否已install supervisord,安装后可查看状态“sudo supervisorctl status”;

$ vi /etc/supervisor/supervisord.conf

; supervisor config file

[unix_http_server]
file=/var/run/supervisor.sock   ; (the path to the socket file)
chmod=0700                       ; sockef file mode (default 0700)

[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor            ; (‘AUTO‘ child log dir, default $TEMP)

; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL  for a unix socket

; The [include] section can just contain the "files" setting.  This
; setting can list multiple files (separated by whitespace or
; newlines).  It can also contain wildcards.  The filenames are
; interpreted as relative to this file.  Included files *cannot*
; include files themselves.

[include]
files = /etc/supervisor/conf.d/*.conf

"

[include]
files = /etc/supervisor/conf.d/*.conf

"

即可在/etc/supervisor/conf.d/ 目录下$vi tornado_demo.conf

[program:tornado_demo]
command=python /var/www/tornado_example/munger/main.py --port=8880
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile = /var/log/munger/munger.log
stderr_logfile = /var/log/munger/error.log

关于tornado

实例使用 http://demo.pythoner.com/itt2zh/ch2.html

2.3 复杂示例:The Alpha Munger 例子即可。

其中 重点需要关注的是supervisord的用法。

1. sudo supervisorctl stop tornado_demo

2. sudo supervisorctl start tornado_demo

3. sudo supervisorctl status

4. sudo /etc/init.d/supervisor start/stop/restart/reload

修改*.conf文件后,需要reload

参考链接:

1. http://gracece.com/2014/03/Tornado-supervisor+nginx/

2. http://blog.csdn.net/tengzhaorong/article/details/12833157

3. https://serholiu.com/tornado-nginx-supervisord

时间: 2024-07-28 12:31:00

tornado + nginx + supervisord 环境部署的相关文章

Flask+Gunicorn+Gevent+Supervisor+Nginx生产环境部署

老毛病了,在用某个新框架或新架构之前,总得花时间谷歌和自己折腾一番,才能知道这个框架和架构的优缺点,才会发现自己最喜欢.用的最顺手的的一种.近期在学习python,这里记录一下自己用的一套python web开发的部署环境. 简介 之所以选择Flask,而没选择用的最多的django,是因为现在这个小项目是一个简单的web工具,提供上传文件.数据处理.并下载的功能.简单小巧,没必要折腾Django.而Flask正好是一个Python实现的Web开发微框架,它基于Werkzeug 和 Jinja2

Ubuntu + Django(DRF) + channels(websocket)+NGINX + uwsgi 环境部署

原来uwsgi并不能启动  asgi  呀!现在才知道,就因为这一点我花了一周时间才成功啊!!!!!!!! 是呀!你启动uwsgi 是将你的项目启动了,可是你也发现虽然启动了,但是你的websocket不能访问???why?? 原因是你的ASGI没有启动 明明你使用python manage.py runserver 是可以访问的,但是为啥部署到服务器上不能访问呢? 原因是uwsgi服务器不能启动ASGI, 但是你启动了WSGI所以可以访问HTTP请求,你可以留意一下启动的日志....坑啊! 要

php+mysql+nginx在linux上的环境部署

一直在linux上鼓捣,还没有完整在linux下配置过nginx服务器环境部署呢,这几天没什么事就部署了一下,遇到的问题也很多,现在把我的环境部署文档发出了,有什么问题大家可以一起讨论一下,希望大家采用后遇到问题多多沟通. || 安装所需各种依赖包 sudo -s LANG=C yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2

Nginx+Gunicorn+virtualenv+supervisord+Postgresql部署Django应用

关于Django应用部署 Django是一个高效.多功能和动态地进化的Web应用开发框架.目前比较流行的部署.运行Django应用方式是基于Apache的mod_wsgi模块,但更加高效.弹性,同时又更加复杂的方式是使用以下工具来部署实施:Nginx.Gunicorn.virtualenv.supervisord.Postgresql.以下详细介绍如何结合这些工具来部署Django应用到Linux上. 准备工作 需要有一台拥有root权限的Linux服务器,这是部署应用的平台.本文采用CentO

Django + Uwsgi + Nginx 的生产环境部署

使用runserver可以使我们的django项目很便捷的在本地运行起来,但这只能在局域网内访问,如果在生产环境部署django,就要多考虑一些问题了.比如静态文件处理,安全,效率等等,本篇文章总结归纳了一下基于uwsgi+Nginx下django项目生产环境的部署 准备条件: 1.确保有一个能够用runserver正常启动的django项目 2.项目已上传到linux 3.linux上已部署好python环境,且已安装好项目所需的模块 安装uwsgi uwsgi是python的一个模块,安装u

docker容器里面各测试环境部署部署脚本(nginx,php,redis,mysql,nodejs)

公司用到的语言,当然还是php为主,不过后台现在都用到nodejs和golang,所以nodesjs和golang都要安装,发觉使用docker还是很好的,只要把环境部署好了,然后打构建成镜像,下次直接就可以生成环境了,不用重新部署.以下为相关服务的部署脚本: nginx: ###上传并解压安装文件:tar zxvf nginx-1.8.0.tar.gz ###进到安装目录:cd nginx-1.8.0 ###编译参数安装: ./configure --user=nginx --group=ng

linux后台服务器开发环境部署配置和验证(nginx+apache+php-fpm+FASTCGI(C/C++))

linux后台服务器开发环境部署配置 引言 背景 随着公司互联网业务的不断增多,开发环境变得越来越复杂,为了便于统一服务器端的开发部署环境,特制定本配置文档. 使用软件 CentOS 6.3(Linux version 2.6.32-279.el6.x86_64) gcc (GCC) 4.4.6 20120305 (Red Hat 4.4.6-4) 本次配置 Nginx 1.5.8 Apache 2.4.7 php 5.3.26 目的 构造WEB前端技术架构,web前端的部署结构技术完全完成.

[部署开发环境]部署django的生成环境nginx+uwsgi+django

#教程 # ubuntu部署django项目 # 部署准备 - ubuntu操作系统 -- vagrant虚拟 - Nginx服务器 -- 安装在ubuntu的web服务器 - uWSGI应用协议服务模块 -- python的uwsgi模块 - python虚拟环境 -- virtualenv - django框架 - nginx 配置(http <--> socket) - uwsgi配置(socket<-->wsgi) - 系统配 详情见图片linux部署django项目图.p

Django1.11+Uwsgi+Nginx的生产环境部署

思路:使用runserver可以使我们的django项目很便捷的在本地运行起来,但是这只能在局域网内访问.正式环境部署的话比较安全,而且静态文件的处理方式会比较友好.nginx作为服务器的最前端,负责接收client的所有请求,静态请求由nginx自己处理,非静态请求通过uwsgi传递给django,由django来进行处理. 准备:1  一个django项目,能用runserver启动: 2 服务器基础环境,python2.7+uwsgi:使用pip install uwsgi安装,nignx