tornadoのsupervisor nginx導入

10763 ワード

tornadoのsupervisor nginx導入
  • ここでは主にtornadoのsupervisorとnginxベースの導入に関する問題
  • について説明します.
    nginx tornado逆プロキシ構成
  • に配置されたモデル図は、次のtornado之supervisor nginx部署_第1张图片
  • である.
    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=7000
    directory=/var/www
    user=www-data
    autorestart=true
    redirect_stderr=true
    stdout_logfile=/var/log/tornado.log
    loglevel=info
    
    [program:tornado-7001]
    command=python /home/wuyong/tornado_learn/hello_module.py --port=7001
    directory=/var/www
    user=www-data
    autorestart=true
    redirect_stderr=true
    stdout_logfile=/var/log/tornado.log
    loglevel=info
    
    [program:tornado-7002]
    command=python /home/wuyong/tornado_learn/hello_module.py --port=7002
    directory=/var/www
    user=www-data
    autorestart=true
    redirect_stderr=true
    stdout_logfile=/var/log/tornado.log
    loglevel=info
    
    [program:tornado-7003]
    command=python /home/wuyong/tornado_learn/hello_module.py --port=7003
    directory=/var/www
    user=www-data
    autorestart=true
    redirect_stderr=true
    stdout_logfile=/var/log/tornado.log
    loglevel=info
  • supervisorのinet_を変更http_server inet_http_server
  • テストされたサービススクリプト
  • import tornado.web
    
    from tornado.options import define, options
    
    
    define("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が正しいかどうかをテストするtornado之supervisor nginx部署_第2张图片
  • ページテストtornado之supervisor nginx部署_第3张图片以上の説明検証成功
  • 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
  • 検証に成功し、ログおよびページアクセスtornado之supervisor nginx部署_第4张图片
  • を表示
    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からhttpリクエスト
  • へ転送
    server {
        listen 80;
        server_name example.com;
    
        rewrite /(.*) https://$http_host/$1 redirect;
    }