写了一个极简单的 web server ,支持:
- 静态文件(相当于标准库 SimpleHTTPServer )
- WSGI 应用 (简单的 WSGI Server )
- 代理到其他 web 服务
- 多线程 /多进程处理请求
代码
https://github.com/RealHacker/python-gems/tree/master/http_server
配置文件
{
"server":{
"ip": "127.0.0.1",
"port": 8000,
"mode": "thread"
},
"routes":{
"/app": {
"type": "wsgi",
"application": "D:/Workspace/Example/wsgi.py"
},
"/app/static": {
"type": "static",
"dir": "D:/workspace/static/"
},
"/app/proxy": {
"type": "proxy",
"proxyurl": "http://www.qq.com/"
}
}
}
设置好 config.json 后,即可执行:
python web_server.py
这个是自己写的原型,所以一定有很多没考虑到的问题,希望有兴趣的可以帮忙跑一下,看看有什么 bug ,或者直接点评代码。良辰在此先行谢过。