Nginx + tornado + supervisor部署
参考链接:supervisor + Tornado + Nginx 使用详解, 用tornado ,Supervisord ,nginx架网站, tornado官方文档
项目文档树:
.
├── chnservices
│ └── channels.py
├── etc
│ ├── chnservices.conf
│ ├── nginx
│ │ └── nginx.conf
│ ├── supervisord.conf
│ └── supervisord.conf.original
└── venv
├── bin
│ ├── activate
│ ├── activate.csh
│ ├── activate.fish
│ ├── activate_this.py
│ ├── easy_install
│ ├── easy_install-2.7
│ ├── pip
│ ├── pip2
│ ├── pip2.
│ ├── python
│ ├── python2 -> python
│ └── python2. -> python
├── include
│ └── python2. -> /usr/include/python2.
├── lib
│ └── python2.
└── local
├── bin -> /a/path/venv/bin
├── include -> /a/path/venv/include
└── lib -> /a/path/venv/lib
supervisor.conf(部分)
[program:app-channels]
process_name=%(program_name)s-%(process_num)s
directory=/a/path/chnservices/
command=/a/path/venv/bin/python2.7 /a/path/chnservices/channels.py --port=%(process_num)s
numprocs=2
numprocs_start=8001
;umask=022
;priority=999
autostart=true
startsecs=2
;startretries=3
;autorestart=unexpected
;exitcodes=0,2
;stopsignal=QUIT
;stopwaitsecs=10
;stopasgroup=false
;killasgroup=false
user=www-data
redirect_stderr=true
stdout_logfile=/var/log/nginx/chn_stdout.log
;stdout_logfile_maxbytes=1MB
;stdout_logfile_backups=10
;stdout_capture_maxbytes=1MB
;stdout_events_enabled=false
stderr_logfile=/var/log/nginx/chn_stderr.log
;stderr_logfile_maxbytes=1MB
;stderr_logfile_backups=10
;stderr_capture_maxbytes=1MB
;stderr_events_enabled=false
;environment=A="",B=""
;serverurl=AUTO
channels.py
import tornado.ioloop
import tornado.web
from tornado.options import define, options define("port", default=8006, help="run on the given port", type=int) class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world") def make_app():
return tornado.web.Application([
(r"/", MainHandler),
]) if __name__ == "__main__":
tornado.options.parse_command_line()
# tornado.options.parse_config_file("/etc/chnservices.conf")
print 'port:',options.port
app = make_app()
app.listen(options.port)
tornado.ioloop.IOLoop.current().start()
nginx.conf(tornado推荐配置修改)
user www-data;
worker_processes 1; error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid; events {
worker_connections 1024;
use epoll;
} http {
# Enumerate all the Tornado servers here
upstream frontends {
server 127.0.0.1:8001;
server 127.0.0.1:8002;
} include /etc/nginx/mime.types;
default_type application/octet-stream; access_log /var/log/nginx/access.log; keepalive_timeout 65;
proxy_read_timeout 200;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
gzip on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain text/html text/css text/xml
application/x-javascript application/xml
application/atom+xml text/javascript; # Only retry if there was a communication error, not a timeout
# on the Tornado server (to avoid propagating "queries of death"
# to all frontends)
proxy_next_upstream error;
proxy_next_upstream error; server {
listen 8000; # Allow file uploads
client_max_body_size 50M; location ^~ /static/ {
root /var/www/tornado/;
if ($query_string) {
expires max;
}
}
location = /favicon.ico {
rewrite (.*) /static/favicon.ico;
}
location = /robots.txt {
rewrite (.*) /static/robots.txt;
} location / {
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;
}
}
}
安装:
使用supervisor做进程管理,使用Nginx做反向代理;supervisor可以使用源码安装和yum安装(CentOS),使用pip安装和源码安装是一样的道理:
sudo pip install supervisor
supervisor默认会从(/usr/local/etc/supervisord.conf, /usr/local/supervisord.conf, supervisord.conf, etc/supervisord.conf, /etc/supervisord.conf)寻找配置文件,为了方便,我们生成配置文件并修改后,链接到/etc/supervisord.conf。
生成配置文件:
echo_supervisord_conf > /a/path/etc/supervisord.conf
按示例修改,修改后链接到指定位置:
sudo ln -s /a/path/etc/chnservices.conf /etc/chnservices.conf
将Nginx配置文件修改后链接到默认位置:
sudo ln -s /a/path/etc/nginx/nginx.conf /etc/nginx/nginx.conf
使Nginx中设置的静态目录与项目的静态目录保持一致:
ln -s /a/path/chnservices /var/www/tornado
启动supervisor:
sudo supervisord -c /etc/supervisord.conf
sudo supervisorctl start all
sudo supervisorctl reload all
sudo supervisorctl restart all
此时,浏览器访问http://127.0.0.1:8001/和http://127.0.0.1:8002/应该就可以看到“Hello, world”了.
启动nginx:
sudo service nginx restart
此时,浏览器访问http://127.0.0.1:8000/就可以看到从tornado经nginx的“Hello, world”了.
添加开机启动:
tornado代码遇到异常退出时supervisor会自动重新启动我们的python代码,但是现在supervisor不是开机启动的,编辑/etc/rc.local, 在exit 0之前添加sudo supervisord即可。
Nginx + tornado + supervisor部署的更多相关文章
- centos7 使用nginx + tornado + supervisor搭建服务
如何在Linux下部署一个简单的基于Nginx+Tornado+Supervisor的Python web服务. Tornado:官方介绍,是使用Python编写出来的一个极轻量级.高可伸缩性和非阻塞 ...
- flask +gevent+nginx+Gunicorn+supervisor部署flask应用
上篇 可以完美部署flask ,但是视乎在结合gevent+apscheduler 实现异步非阻塞后台和定时任务的时候视乎不是那么完美.请教了前辈,决定使用flask+gevent+nginx+g ...
- CentOS 下部署Nginx+Gunicorn+Supervisor部署Flask项目
原本之前有一部分东西是在Windows Server,但是由于Gunicorn不支持Windows部署起来颇为麻烦.最近转战CentOS,折腾一段时间,终于简单部署成功.CentOS新手,作为一个总结 ...
- Nginx+Gunicorn+Supervisor部署Flask应用
Flask 内置了简单的 Web 环境,让我们在开发的时候只需要专注于应用实现,而真正要在生产环境运行时这个简单的 Web 环境就不够用了,还需要一系列操作才能让 Web 应用高效的运行起来.现在记录 ...
- 部署项目Nginx+Tornado+Supervisor
http://www.jianshu.com/p/9bebb99368ea Tornado Tornado 和现在的主流 Web 服务器框架(包括大多数 Python 的框架)有着明显的区别:它是非阻 ...
- 给我一台全新的服务器,使用nginx+gunicorn+supervisor部署django
0.准备工作 在一台全新的服务器中新建用户以及用户的工作目录,之后的操作都以这个用户的身份进行,而不是直接用root. 举个栗子: 在服务器下新建用户rinka并赋予sudo权限 1) root登陆, ...
- Python基础 - Ubuntu+Nginx+uwsgi+supervisor部署Flask应用
网上找了许多讲关于Flask应用部署的文章几乎都是一个helloworld的Demo,按照helloworld来部署都没问题,但实际项目部署时还是遇到了不少问题.在这里简单写下自己成功部署的过程,防止 ...
- flask部署:Ubuntu下使用nginx+uwsgi+supervisor部署flask应用
之前一直用的Centos或者Red hat,自从使用Ubuntu后,发现Ubuntu使用起来更方便,自此爱上Ubuntu. 一.从github上下载flask应用 1.我已经成功将自己编写好的应用上传 ...
- 2020最新nginx+gunicorn+supervisor部署基于flask开发的项目的生产环境的详细攻略
本攻略基于ubuntu1804的版本,服务器用的华为云的服务器,python3(python2已经在2020彻底停止维护了,所以转到python3是必须的)欢迎加我的QQ6398903,或QQ群讨论相 ...
随机推荐
- CyclicBarrier类合唱演绎
package a.jery; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.ExecutorServi ...
- Oracle中的表构造导出到word Sql语句
select * from ( SELECT t1.Table_Name AS "表名称", t3.comments AS "表说明", t1.Column_ ...
- [转]CABasicAnimation用法
CABasicAnimation用法 CABasicAnimation 自己只有三个property fromValue toValue ByValue 当你创建一个 CABasicAni ...
- JSP+Servlet中使用cos.jar进行图片上传(文件上传亦然)
链接:JSP+Servlet中使用jspsmartupload.jar进行图片上传下载 关于cos.jar,百度百科只有这么几句话(http://baike.baidu.com/subview/406 ...
- VBA_Excel_教程:过程,函数
Sub s1() Debug.Print "s1" '调用过程:无括号,加call提升可读性 s2 Call s2 End Sub Sub s2() Debug.Print &qu ...
- 【练习】移动数据----infile *
要求: ①指定bad文件: ②挂在之前将目标表delete: ③导入的的数据在控制文件中. 1.创建目录对象: :: SYS@ORA11GR2>create or replace directo ...
- JQuery的Ajax跨域请求原理概述及实例
今天在项目中需要做远程数据加载并渲染页面,直到开发阶段才意识到ajax跨域请求的问题,隐约记得Jquery有提过一个ajax跨域请求的解决方式,于是即刻翻出Jquery的API出来研究,发 JQuer ...
- Visual paradigm Db Archtecture Database config
- Unity IoC Container创建对象过程
Unity是微软P&P推出的一个开源的IoC框架,最新的官方版本是2.0.Unity之前的版本建立在一个称为ObjectBuild的组件上,熟悉EnterLib的读者,相信对ObjectBui ...
- angularJS学习之旅(1)
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...