• nginx+uwsgi+WSGI applications


    uwsgi一个专业的部署运用的工具,不仅能够部署Python运用,还能够部署其他运用比如Perl,Ruby等

    uWSGI

    安装:

    1 pip install uwsgi


    WSGI application(关于WSGI规范请参看,我前面讲解的一篇WSGI文章)命名为 foobar.py

    1 def application(env, start_response):
    2     start_response('200 OK', [('Content-Type','text/html')])
    3     method = env['REQUEST_METHOD']
    4     path   = env['PATH_INFO']
    5     yield path
    6     yield '<br/>'
    7     yield method
    8     yield '<br/>'
    9     yield 'Hello World'

    nginx配置(这里配置任何以.py结尾的都使用WSGI application处理)

    1         location  ~.py    {
    2             include       uwsgi_params;
    3             uwsgi_pass    localhost:9000;
    4         }

    使用uWSGI部署 wsgi application

    uwsgi --socket 127.0.0.1:9000 --wsgi-file foobar.py --master --processes 4 --threads 2 --stats 127.0.0.1:9191

     --wsgi-file 指定 wsgi application 文件

    --master 指定一个管理进程,当进程死后,重新生成进程

    --processes 指定进程数量

    --threads  指定每个进程中线程的个数

    --stats      指定统计数据的主机,使用telnet 127.0.0.1 9191 后你将会得到一个JSON格式的数据,里面主要存储额各个进程和线程的信息

     也可以使用一个配置文件启动,详情参考uwsgi的文档

    使用localhost/test.py或者localhost/home/test.py 任何以.py结尾的请求,浏览器将会显示请求的方法和路径

  • 相关阅读:
    IPC之PIPE
    MSChart的研究(转)
    计算机信息类ComputerInfo(车)
    c# 操作Word总结(车)
    js跳转页面(转)
    textarea中的回车识别问题
    js的页面传值cookie.session
    destoon使用
    vscode 配置php
    vscode开发c#
  • 原文地址:https://www.cnblogs.com/ArtsCrafts/p/uwsgi_1.html
Copyright © 2020-2023  润新知