如何使用gunicorn运行Django遗留项目?

时间:2017-05-18 15:59:56

标签: django gunicorn ubuntu-17.04

如何使用gunicorn运行django项目1.5的遗产?

$ gunicorn wsgi:application -b 127.0.0.1:8000
[2017-05-18 16:48:00 +0000] [15535] [INFO] Starting gunicorn 19.6.0
[2017-05-18 16:48:00 +0000] [15535] [INFO] Listening at: http://127.0.0.1:8000 (15535)
[2017-05-18 16:48:00 +0000] [15535] [INFO] Using worker: sync
[2017-05-18 16:48:00 +0000] [15539] [INFO] Booting worker with pid: 15539
[2017-05-18 16:48:00 +0000] [15539] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 557, 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 136, 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 384, in import_app
    __import__(module)
ImportError: No module named wsgi
[2017-05-18 16:48:00 +0000] [15539] [INFO] Worker exiting (pid: 15539)
[2017-05-18 16:48:00 +0000] [15535] [INFO] Shutting down: Master
[2017-05-18 16:48:00 +0000] [15535] [INFO] Reason: Worker failed to boot.

这是我在开发模式下运行它的方式:

$ python manage.py runserver
>>> Starting gulp watch
>>> gulp watch gulp process on pid 15935
Validating models...

0 errors found
May 18, 2017 - 16:53:39
Django version 1.5.12, using settings 'website.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[16:53:39] Warning: gulp version mismatch:
[16:53:39] Global gulp is 3.9.1
[16:53:39] Local gulp is 3.5.6
[16:53:39] Using gulpfile /var/www/html/legacy-project/gulpfile.js
[16:53:39] Starting 'sass'...
[16:53:40] Finished 'sass' after 118 ms
[16:53:40] Starting 'watch'...
[16:53:40] Finished 'watch' after 223 ms
[16:53:40] Live reload server listening on: 35729

它运作正常。但我被告知我不应该像生产服务器那样运行它。我应该使用gunicorn

我是Django项目的新手,我从之前的开发人员那里学习这个项目。他们没有给我提供将其迁移到新服务器的适当说明。

如何使用gunicorn正确运行它?

修改

$ gunicorn my-django.wsgi
[2017-05-18 17:40:16 +0000] [19389] [INFO] Starting gunicorn 19.6.0
[2017-05-18 17:40:16 +0000] [19389] [INFO] Listening at: http://127.0.0.1:8000 (19389)
[2017-05-18 17:40:16 +0000] [19389] [INFO] Using worker: sync
[2017-05-18 17:40:16 +0000] [19393] [INFO] Booting worker with pid: 19393
[2017-05-18 17:40:16 +0000] [19393] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 557, 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 136, 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 384, in import_app
    __import__(module)
ImportError: No module named my-django.wsgi
[2017-05-18 17:40:16 +0000] [19393] [INFO] Worker exiting (pid: 19393)
[2017-05-18 17:40:16 +0000] [19389] [INFO] Shutting down: Master
[2017-05-18 17:40:16 +0000] [19389] [INFO] Reason: Worker failed to boot.

0 个答案:

没有答案