WSGI接口

wsgi是将python服务器程序连接到web服务器的通用协议。uwsgi是独立的实现了wsgi协议的服务器。

 
web服务器
服务端程序

简化版的WSGI架构

服务端程序(类似django的角色)

新建webapp.py

  1.  
    # coding=utf-8
  2.  
     
  3.  
    # 简化版的服务端程序
  4.  
    def application(environ, start_response):
  5.  
    start_response('200 OK', [('Conteng-Type-TYpe', 'text/html')])
  6.  
    return '<b>Hello,world!</b>'

wsgi程序

新建wsgis_service.py

  1.  
    # coding=utf-8
  2.  
    from wsgiref.simple_server import make_server
  3.  
     
  4.  
    from wsgi.webapp import application
  5.  
     
  6.  
    # 实例化一个wsgi服务器
  7.  
    server = make_server('', 8080, application)
  8.  
    # 开始监听
  9.  
    server.serve_forever()
  10.  
     

测试

/usr/bin/python2.7 wsgis_service.py

一个最简化的wsgi架构就完成了.

常用的wsgi服务器-uwsgi

一般都不用自己实现wsgi服务。都使用uwsgi。

安装

pip install uwsgi

使用uwsgi.ini文件

  1.  
    [uwsgi]
  2.  
    http = 8080
  3.  
    wsgi-file = /home/xyl/code/ppmoney/script_store/wsgi/webapp.py

验证

uwsgi uwsgi.ini

相关文章:

  • 2021-11-13
  • 2021-11-29
  • 2022-01-04
  • 2021-10-28
  • 2021-11-05
  • 2022-12-23
  • 2022-12-23
  • 2021-04-04
猜你喜欢
  • 2021-11-13
  • 2021-09-25
  • 2022-12-23
  • 2021-06-24
  • 2022-12-23
  • 2021-08-10
相关资源
相似解决方案