tornado之supervisor nginx部署

来源:互联网 发布:医院网络拓扑结构图 编辑:程序博客网 时间:2024/05/29 00:34

tornado之supervisor nginx部署

  • 本文主要介绍tornado基于supervisor和nginx的部署问题

nginx tornado反向代理配置

  • 部署的模型图如下
    tornado_nginx部署

supervisor安装

  • supervisor入门地址
http://blog.csdn.net/ricky110/article/details/77430387
  • 配置(新建tornado.conf)
[group:tornadoes]programs=tornado-7000,tornado-7001,tornado-7002,tornado-7003[program:tornado-7000]command=python /home/wuyong/tornado_learn/hello_module.py --port=7000directory=/var/wwwuser=www-dataautorestart=trueredirect_stderr=truestdout_logfile=/var/log/tornado.logloglevel=info[program:tornado-7001]command=python /home/wuyong/tornado_learn/hello_module.py --port=7001directory=/var/wwwuser=www-dataautorestart=trueredirect_stderr=truestdout_logfile=/var/log/tornado.logloglevel=info[program:tornado-7002]command=python /home/wuyong/tornado_learn/hello_module.py --port=7002directory=/var/wwwuser=www-dataautorestart=trueredirect_stderr=truestdout_logfile=/var/log/tornado.logloglevel=info[program:tornado-7003]command=python /home/wuyong/tornado_learn/hello_module.py --port=7003directory=/var/wwwuser=www-dataautorestart=trueredirect_stderr=truestdout_logfile=/var/log/tornado.logloglevel=info
  • 修改supervisor的inet_http_server
    inet_http_server
  • 被测试的服务脚本
import tornado.webfrom tornado.options import define, optionsdefine("port", default=8000, help="run on the given port", type=int)class IndexHandler(tornado.web.RequestHandler):    def get(self):        greeting = self.get_argument('greeting', 'Hello')        self.write(greeting + ', friendly user!')if __name__ == "__main__":    tornado.options.parse_command_line()    app = tornado.web.Application(handlers=[(r"/", IndexHandler)])    http_server = tornado.httpserver.HTTPServer(app)    http_server.listen(options.port)    tornado.ioloop.IOLoop.instance().start()
  • 测试验证supervisor是否正确
    test_supervisor_tornado
  • 页面测试
    test_super_success.
    以上说明验证成功

nginx搭建

  • nginx安装 apt-get install nginx

  • 修改配置 cd /etc/nginx && vim tornado_nginx.conf加入以下配置,将后端上游服务upstream指定好

proxy_next_upstream error;upstream tornadoes {    server 127.0.0.1:7000;    server 127.0.0.1:7001;    server 127.0.0.1:7002;    server 127.0.0.1:7003;}server {    listen 81;    location /static/ {        root /var/www/static;        if ($query_string) {            expires max;        }    }    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://tornadoes;    }}
  • 运行
    /usr/sbin/nginx

  • 验证成功,查看日志及页面访问
    yz_nginx.

https

  • nginx ssl解密配置
server {    listen 443;    ssl on;    ssl_certificate /path/to/cert.pem;    ssl_certificate_key /path/to/cert.key;    default_type application/octet-stream;    location /static/ {        root /var/www/static;        if ($query_string) {            expires max;        }    }    location = /favicon.ico {        rewrite (.*) /static/favicon.ico;    }    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://tornadoes;    }}
  • nginx 转发http到https请求
server {    listen 80;    server_name example.com;    rewrite /(.*) https://$http_host/$1 redirect;}
原创粉丝点击