【问题标题】:How to use WSGI with a Python/Flask App -- HasGeek Lastuser?如何在 Python/Flask 应用程序中使用 WSGI——HasGeek Lastuser?
【发布时间】:2014-04-04 12:34:53
【问题描述】:

我正在尝试在我的机器上设置一个 lastuser OAuth 服务器。所以我打算用 SSL(在 443 上)和lastuser 应用程序设置 Nginx 作为 WSGI 服务器。

HasGeek lastuser

我有setup HTTPS/SSL with Nginx,它在我的机器上运行良好。

但是 WSGI 服务器不工作。

Lastuser 基本上是一个带有 WSGI 脚本 website.wsgi 的 Flask 应用程序。

import sys
import os.path
sys.path.insert(0, os.path.dirname(__file__))
from lastuserapp import app as application, init_for
init_for('production')

我尝试将 gunicorn 用于 WSGI,但收到错误 ImportError: No module named wsgi,如下所示:

$ gunicorn -b localhost:7000  website.wsgi 
2014-03-03 17:06:49 [31267] [INFO] Starting gunicorn 0.13.4
2014-03-03 17:06:49 [31267] [INFO] Listening at: http://127.0.0.1:7000 (31267)
2014-03-03 17:06:49 [31267] [INFO] Using worker: sync
2014-03-03 17:06:49 [31270] [INFO] Booting worker with pid: 31270
2014-03-03 17:06:50 [31270] [ERROR] Exception in worker process:
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.7/gunicorn/arbiter.py", line 456, in spawn_worker
    worker.init_process()
  File "/usr/lib/pymodules/python2.7/gunicorn/workers/base.py", line 100, in init_process
    self.wsgi = self.app.wsgi()
  File "/usr/lib/pymodules/python2.7/gunicorn/app/base.py", line 101, in wsgi
    self.callable = self.load()
  File "/usr/lib/pymodules/python2.7/gunicorn/app/wsgiapp.py", line 24, in load
    return util.import_app(self.app_uri)
  File "/usr/lib/pymodules/python2.7/gunicorn/util.py", line 241, in import_app
    __import__(module)
ImportError: No module named wsgi
2014-03-03 17:06:50 [31270] [INFO] Worker exiting (pid: 31270)
2014-03-03 17:06:50 [31267] [INFO] Shutting down: Master
2014-03-03 17:06:50 [31267] [INFO] Reason: Worker failed to boot.

所以我的问题是:我做错了什么还是 gnunicorn 或我机器上安装的库有问题?

【问题讨论】:

    标签: python nginx flask wsgi gunicorn


    【解决方案1】:

    Gunicorn 正在 website 模块中寻找 wsgi 模块,但该模块不存在。这就是为什么在同一个文件夹中有一个相同的website.py 文件。改为调用它(没有 .py 扩展名)。

    website.wsgi 用于 Apache 的 mod_wsgi,因为它需要 .wsgi 扩展。

    【讨论】:

    • 如果你使用 WSGIScriptAlias 指令来配置 mod_wsgi,它并不关心 WSGI 脚本文件扩展名是什么。
    • 有趣。那么我可以从我的存储库中删除多余的website.wsgi 文件吗?
    猜你喜欢
    • 1970-01-01
    • 2019-11-17
    • 2018-10-28
    • 2021-10-18
    • 1970-01-01
    • 2021-05-20
    • 1970-01-01
    • 2015-11-21
    • 2019-08-17
    相关资源
    最近更新 更多