我有一个django应用,尝试先与gunicorn设置,然后再与supervisor和nginx设置。
该应用程序使用正常的django命令运行,就像 python manage.py runserver
我使用pip likepip install gunicorn
和Django版本安装了gunicorn1.5.3
当我在虚拟环境中运行以下命令时,如下所示
gunicorn hello.wsgi:application -b xx.xxx.xxx.xx:8000
面对错误
Traceback (most recent call last):
File "/root/Envs/proj/bin/gunicorn", line 9, in <module>
load_entry_point('gunicorn==19.0.0', 'console_scripts', 'gunicorn')()
File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 166, in run
super(Application, self).run()
File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 71, in run
Arbiter(self).run()
File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 169, in run
self.manage_workers()
File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 477, in manage_workers
self.spawn_workers()
File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 537, in spawn_workers
time.sleep(0.1 * random.random())
File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 209, in handle_chld
self.reap_workers()
File "/root/Envs/proj/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>
那么,为什么实际上会遇到上述错误?解决方法是什么?
实际上,这里的问题是wsgi文件本身,在django
1.3之前,该wsgi文件以扩展名命名.wsgi
,但是现在在最新版本中将以.py
wsgi文件创建,扩展名是wsgi文件必须是python模块
所以文件应该是hello_wsgi.py
,命令应该是
gunicorn hello:application -b xx.xxx.xxx.xx:8000