【问题标题】:Deploy flask in production with GeventWSGI and Nginx使用 GeventWSGI 和 Nginx 在生产环境中部署烧瓶
【发布时间】:2015-12-27 15:06:54
【问题描述】:

我实际上有一个用 python 编写的带有 flask 和 flaskrestful 扩展的 rest api。 我使用 gevent WSGI

def runserver():
api.debug = True
http_server = WSGIServer(('', 5000), api)
http_server.start()

在我的机器上,一切都像魅力一样。 我想在 linux vm 上进行生产,在互联网上搜索了几个小时,我没有选择 mod_wsgi,因为 gevent 不能正常工作,所以我更喜欢使用 nginx。

在互联网上我看到使用 uWSGI 托管的烧瓶应用程序,我的回答是我需要使用 uWSGI? 即使我在我的烧瓶应用程序中使用 geventWSGI? 如何使用这个? 如果我不需要 uWSGI,我只需要配置 nginx 站点即可将请求正确传递给我的烧瓶应用程序? 我是这一切的新手,所以我有点困惑。

提前致谢

【问题讨论】:

    标签: python nginx deployment wsgi gevent


    【解决方案1】:

    你可以在 Gevent 模式http://uwsgi-docs.readthedocs.org/en/latest/Gevent.html 下运行 Uwsgi,然后通过 nginx 将所有烧瓶请求路由到它。

           server {
              listen 80;
              server_name customersite1.com;
              access_log /var/log/customersite1/access_log;
              location / {
              root /var/www/customersite1;
              uwsgi_pass 127.0.0.1:3031;
              include uwsgi_params;
              }
    

    查看http://uwsgi-docs.readthedocs.org/en/latest/Nginx.html了解更多详情

    【讨论】:

    • 首先感谢您的回答,我有几个问题,当我使用 uwsgi 或 gunicorn 然后我使用 nginx 代理时,我准备好生产了吗?除了猴子补丁之外,我不能更改代码中的任何内容?我也可以使用默认烧瓶 wsgi?然后包裹成 gunicorn 或 wsgi?谢谢
    • 是的,您已经准备好进行生产,除了猴子补丁之外,您不必更改您的代码中的任何内容,您也可以使用默认的烧瓶服务器,如果那是您所要求的,然后切换到uwsgi,你能把答案标记为正确并投票吗?
    猜你喜欢
    • 1970-01-01
    • 2015-01-12
    • 2019-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-19
    • 1970-01-01
    相关资源
    最近更新 更多