如何运行与 gunicorn 绑定的 django 应用程序?
Posted
技术标签:
【中文标题】如何运行与 gunicorn 绑定的 django 应用程序?【英文标题】:how to run django app binded with gunicorn? 【发布时间】:2019-09-27 23:45:41 【问题描述】:我正在尝试按照通过此链接发布的教程运行与 gunicorn 和 nginx 绑定的预构建 django 项目。
How To Set Up Django with Postgres, Nginx, and Gunicorn on Ubuntu 18.04
项目文件夹上的树命令给出了这个输出。
当我使用# python manage.py runserver
发布项目时,我可以查看其内容。但是当我尝试使用 unicorn 和以下命令绑定它时,它会显示以下错误。
# gunicorn --bind 0.0.0.0:8000 DjangoWebsiteSample.eccomerceProject.wsgi.py
[2019-05-10 05:25:11 +0000] [1912] [INFO] Starting gunicorn 19.7.1
[2019-05-10 05:25:11 +0000] [1912] [INFO] Listening at: http://0.0.0.0:8000 (1912)
[2019-05-10 05:25:11 +0000] [1912] [INFO] Using worker: sync
[2019-05-10 05:25:11 +0000] [1916] [INFO] Booting worker with pid: 1916
[2019-05-10 05:25:11 +0000] [1916] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 578, in spawn_worker
worker.init_process()
File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 126, in init_process
self.load_wsgi()
File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 135, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/lib/python2.7/dist-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/lib/python2.7/dist-packages/gunicorn/util.py", line 377, in import_app
__import__(module)
ImportError: No module named DjangoWebsiteSample.eccomerceProject.wsgi.py
[2019-05-10 05:25:11 +0000] [1916] [INFO] Worker exiting (pid: 1916)
[2019-05-10 05:25:11 +0000] [1912] [INFO] Shutting down: Master
[2019-05-10 05:25:11 +0000] [1912] [INFO] Reason: Worker failed to boot.
【问题讨论】:
【参考方案1】:试试这个命令:
gunicorn --bind 0.0.0.0:8000 eccomerceProject.wsgi
【讨论】:
以上是关于如何运行与 gunicorn 绑定的 django 应用程序?的主要内容,如果未能解决你的问题,请参考以下文章
如何运行多个Django App Gunicorn systemd?
如何从不是 django 项目文件夹的文件夹中运行 gunicorn
如何使用 gunicorn 为 django 配置 nginx?
使用 nginx gunicorn 在 digitalocean 上部署 django react