python Django监督+Gunicorn+Nginx -导入错误:没有名为backend.wsgi的模块

olhwl3o2  于 2023-01-16  发布在  Python
关注(0)|答案(1)|浏览(140)

我得到了下面的错误日志,其中backend当然是我的Django项目的名称。我看了SO上的其他相关Q/A,但没有得到相关的东西。

[2015-07-12 12:18:04 +0000] [17089] [INFO] Starting gunicorn 19.3.0
[2015-07-12 12:18:04 +0000] [17089] [INFO] Listening at: http://127.0.0.1:8002 (17089)
[2015-07-12 12:18:04 +0000] [17089] [INFO] Using worker: sync
[2015-07-12 12:18:04 +0000] [17098] [INFO] Booting worker with pid: 17098
[2015-07-12 12:18:04 +0000] [17098] [ERROR] Exception in worker process:
Traceback (most recent call last):
  File "/home/ubuntu/.virtualenvs/backend/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
    worker.init_process()
  File "/home/ubuntu/.virtualenvs/backend/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 118, in init_process
    self.wsgi = self.app.wsgi()
  File "/home/ubuntu/.virtualenvs/backend/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/home/ubuntu/.virtualenvs/backend/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/home/ubuntu/.virtualenvs/backend/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/home/ubuntu/.virtualenvs/backend/local/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
    __import__(module)
ImportError: No module named backend.wsgi
Traceback (most recent call last):
  File "/home/ubuntu/.virtualenvs/backend/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker
    worker.init_process()
  File "/home/ubuntu/.virtualenvs/backend/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 118, in init_process
    self.wsgi = self.app.wsgi()
  File "/home/ubuntu/.virtualenvs/backend/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/home/ubuntu/.virtualenvs/backend/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/home/ubuntu/.virtualenvs/backend/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/home/ubuntu/.virtualenvs/backend/local/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app
    __import__(module)
ImportError: No module named backend.wsgi
[2015-07-12 12:18:04 +0000] [17098] [INFO] Worker exiting (pid: 17098)
Traceback (most recent call last):
  File "/home/ubuntu/.virtualenvs/backend/bin/gunicorn", line 11, in <module>
    sys.exit(run())
  File "/home/ubuntu/.virtualenvs/backend/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
    WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
  File "/home/ubuntu/.virtualenvs/backend/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 189, in run
    super(Application, self).run()
  File "/home/ubuntu/.virtualenvs/backend/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 72, in run
    Arbiter(self).run()
  File "/home/ubuntu/.virtualenvs/backend/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 174, in run
    self.manage_workers()
  File "/home/ubuntu/.virtualenvs/backend/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 477, in manage_workers
    self.spawn_workers()
  File "/home/ubuntu/.virtualenvs/backend/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 541, in spawn_workers
    time.sleep(0.1 * random.random())
  File "/home/ubuntu/.virtualenvs/backend/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 214, in handle_chld
    self.reap_workers()
  File "/home/ubuntu/.virtualenvs/backend/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 459, in reap_workers
    raise HaltServer(reason, self.WORKER_BOOT_ERROR)
gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>

如果你需要一些其他的信息,让我知道。编辑:主管会议

[program:%(PROJECT_NAME)s]
command=%(PROJECT_PATH)s/start_gunicorn.bash
directory=%(PROJECT_PATH)s
user=www-data
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=%(PROJECT_PATH)s/logs/supervisorconf.log

开始_gunicorn.bash

#!/bin/bash
# Starts the Gunicorn server
set -e

# Activate the virtualenv for this project
%(ACTIVATE)s

# Start gunicorn going
exec gunicorn %(PROJECT_NAME)s.wsgi:application -c %(PROJECT_PATH)s/gunicorn.conf.py
lf3rwulv

lf3rwulv1#

我的django + react + gunicorn项目也有类似的问题,它是用docker构建的。
真实的的原因是包含WSGI应用程序的模块的位置。启动gunicorn服务器的命令应该运行inside the Django main project directory
start_gunicorn.bash的正确工作流程应如下所示:

#!/bin/bash
# Starts the Gunicorn server
set -e

# Activate the virtualenv for this project
%(ACTIVATE)s

# Change directory
cd course 

# Start gunicorn going
exec gunicorn course.wsgi

相关问题