一 python使用web.py创建web服务有两种方式:
1 使用通常的web方式:
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
from web import wsgiserver
import web
from core.main import main
web.config.debug = False
urls = ('/', 'main')
app = web.application(urls, globals())
if __name__ == "__main__":
port = int(sys.argv[1])
application = web.application(urls, globals()).wsgifunc()
wsgiserver.CherryPyWSGIServer(('0.0.0.0', port), application).start()
2使用gevent的wsgi创建web服务:
from gevent import monkey
monkey.patch_all()
from gevent.wsgi import WSGIServer
from core.main import main
import web
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
web.config.debug = False
urls = ('/', 'main')
app = web.application(urls, globals())
if __name__ == "__main__":
port = int(sys.argv[1])
application = web.application(urls, globals()).wsgifunc()
WSGIServer(('', port), application).serve_forever()
3 创建服务完成后,使用nginx代理进行数据分发
4参考资料:
http://stackoverflow.com/questions/1078599/deploying-a-web-py-application-with-wsgi-several-servers (wsgi)
http://webpy.org/tutorial3.zh-cn (web.py 3.0)