5d6d网 发表于 2015-12-3 11:43:13

使用gunicorn部署python web

  gunicorn 是一款支持wsgi的web服务器, 支持gevent
  首先安装setuptools.wget https://bootstrap.pypa.io/ez_setup.py
  $python ez_setup.py
  $easy_install pip
  $pip install gevent
  $pip install gunicorn
  $apt-get install libmysqld-dev
  $pip install MySQL-python
  
  安装完成后 既可以直接执行 gunicorn code:application   code是的你代码文件。。 application是wsgifunc 默认使用的是8000端口
  如flask:
  core.py



1 from flask import Flask
2 app = Flask(__name__)
3
4 @app.route('/')
5 def hello_world():
6   return 'Hello World!'
  运行方法:gunicorn core:app
  浏览器访问localhost:8000
  可用的参数:
  gunicorn -b 127.0.0.1:8080 core:app绑定端口
  gunicorn -w 8 core:app开启多进程。
  gunicorn -k gevent core:app 使用gevent模式
  
  完成后, 配合nginx Supervisor(进程管理工具)即可搭建出健壮的服务器。
  
页: [1]
查看完整版本: 使用gunicorn部署python web