WSGI Server(uwsgi原理)

WSGI Server

server.py

from wsgiref.simple_server import make_server
from app import application

httpd = make_server('0.0.0.0', 8080, application)
print('start http server 8080...')

httpd.serve_forever()

app.py

def application(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/html')])
    print(environ['PATH_INFO'])
    body = '

Hello, %s!

' % (environ['PATH_INFO'][1:] or 'web') return [body.encode('utf-8')]

好了,打开浏览器,输入127.0.0.1:8080/helloworld/

注意,server.py运行时可能会卡住,可以反复运行一次,浏览器就能访问到了

任何复杂的web服务,本质还是源于此

你可能感兴趣的:(WSGI Server(uwsgi原理))