【问题标题】:gunicorn fails to start when trying to start [duplicate]gunicorn 尝试启动时无法启动[重复]
【发布时间】:2014-06-12 17:24:05
【问题描述】:

我通过如下命令手动启动 nginx/gunicorn:

sudo nginx -c /etc/nginx/nginx.conf; sudo /usr/local/bin/gunicorn -c /home/user/virtualenv/gunicorn_config.py mydjangoproject.wsgi;

我也检查了三次路径,但是当我执行上面的这个命令时,它似乎找不到我的 django 项目 (mydjangoproject)。

我仔细检查了sys.path,它确实包含了我的项目路径(所以我的项目在pythonpath

我得到如下输出:

[3207] [INFO] Starting gunicorn 18.0
[3207] [INFO] Listening at: http://127.0.0.1:8001 (3207)
[3207] [INFO] Using worker: sync
[INFO] Booting worker with pid: 3212
[ERROR] Exception in worker process:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 495, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 106, in init_process
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/base.py", line 114, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 62, in load
    return self.load_wsgiapp()
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python2.7/dist-packages/gunicorn/util.py", line 354, in import_app
    __import__(module)
ImportError: No module named mydjangoproject.wsgi
gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>

Nginx 在这里开始很好,它的gunicorn 似乎无法识别我的 django 项目。

谁能看到可能出了什么问题?

谢谢

【问题讨论】:

  • 我认为您不应该使用 sudo 来启动 gunicorn。而且我还认为您需要将完整路径传递给您的 WSGI 文件。

标签: python django nginx gunicorn


【解决方案1】:

感谢用户Mik.ro 对这篇文章的建议: How to debug gunicorn failure issues?(Worker failed to boot)

你需要在manage.py所在的地方执行这个

【讨论】: