通过Gevent+Apache(反向代理)部署Flask应用

1. 安装gevent

Windows下的话有exe包的,先装greenlet,再装gevent

Debian下先安装libevent

cd /tmp
wget https://github.com/downloads/libevent/libevent/libevent-2.0.20-stable.tar.gz
tar zxvf libevent-2.0.20-stable.tar.gz
cd libevent-2.0.20-stable
./configure --prefix=/usr/local/libevent --enable-shared
make
make check

make install

再安装gevent

pip install gevent
2. 安装Apache

详细步骤请参考

3. 修改Apache配置文件,重启Apache

示例文件:/etc/apache2/sites-available/example.net

<VirtualHost *:80>
     ServerAdmin admin@example.org
     ServerName example.org
     ServerAlias www.example.org
     DocumentRoot /srv/www/example.org/public_html/
     ErrorLog /srv/www/example.org/logs/error.log
     CustomLog /srv/www/example.org/logs/access.log combined
     ProxyRequests Off 
     <Proxy *> 
         Order deny,allow 
         Allow from all 
     </Proxy> 
     ProxyPass / http://127.0.0.1:9000/
     ProxyPassReverse / http://127.0.0.1:9000/

</VirtualHost>

重启Apache

/etc/init.d/apache2 reload

/etc/init.d/apache2 restart
4. 修改Flask项目下的执行文件(run.py)
@manager.command

def rungevent(port=9000, name=''):
    from gevent.wsgi import WSGIServer
    """
    from werkzeug.debug import DebuggedApplication
    app.wsgi_app=DebuggedApplication(app.wsgi_app,True)
    app.debug = True
    """
    server = WSGIServer((name, port), 
                        app)
    server.serve_forever()
5. 在virtualenv的环境下后台加载Flask项目
nohup python run.py rungevent
6. 停止Flask网站时的操作

执行命令列出所有Linux进程。

ps -aux

找到nohup python进程并记住进程pid。

执行命令

kill [进程pid]

立即中止。

转载于:https://www.cnblogs.com/zhiguan/archive/2013/05/20/gevent_apache_flask_deployment.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值