我一直在尝试使用nginx和gunicorn部署django,目前遇到了一个问题,我遵循了SO建议的建议,我已经尝试过这种方式,建议在gunicorn文档中,但仍然没有工作…
(env)nathann@localhost:~/ipals$ ls -l
total 12
drwxrwxr-x 14 nathann nathann 4096 Aug 21 17:32 apps
-rw-rw-r-- 1 nathann nathann 1590 Aug 21 17:55 ipals_wsgi.py
-rw-rw-r-- 1 nathann nathann 1091 Aug 21 17:32 README.md
(env)nathann@localhost:~/ipals$ gunicorn ipals:application -b 127.0.0.1:8001
Traceback (most recent call last):
File "/home/nathann/env/bin/gunicorn", line 11, in <module>
sys.exit(run())
File "/home/nathann/env/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
File "/home/nathann/env/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 185, in run
super(Application, self).run()
File "/home/nathann/env/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 71, in run
Arbiter(self).run()
File "/home/nathann/env/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 169, in run
self.manage_workers()
File "/home/nathann/env/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 477, in manage_workers
self.spawn_workers()
File "/home/nathann/env/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 542, in spawn_workers
time.sleep(0.1 * random.random())
File "/home/nathann/env/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 209, in handle_chld
self.reap_workers()
File "/home/nathann/env/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>
ipals_wsgi.py
import sys
import os
import os.path
# assume we(this file) exist as a sibling to the CODE_DIR
OUR_DIR = os.path.abspath(os.path.dirname(__file__))
# apps dir is our sibling. That's where our apps are.
APPS_DIR = os.path.join(OUR_DIR, 'apps')
# env dir is also a sibling to us and ipals
ENV_DIR = os.path.join(OUR_DIR, '../env')
# activate the virtualenv
activate_this = os.path.join(ENV_DIR, 'bin', 'activate_this.py')
execfile(activate_this, dict(__file__=activate_this))
# add the apps directory to the python path
sys.path.insert(0, APPS_DIR)
# load up django
# from django.core.management import execute_manager
from django.core.handlers.wsgi import WSGIHandler
# tell django to find settings at APPS_DIR/mainsite/settings.py'
#os.environ['DJANGO_SETTINGS_MODULE'] = 'ipals.settings_production'
os.environ['DJANGO_SETTINGS_MODULE'] = 'ipals.settings'
# hand off to the wsgi application
application = WSGIHandler()
我不知道为什么你有一个名为ipals_wsgi.py
的文件,它似乎在项目的顶层,或者你的设置文件在哪里。通常,Django的startproject
命令会创建一个与项目同名的子目录,并在该子目录下的settings.py
旁边放置一个名为wsgi.py
的文件。你似乎已经修改了,但我不明白为什么。
无论如何,您的wsgi文件被调用的事实指出了问题所在:您告诉gunicorn查找一个名为ipals
的文件,但如前所述,该文件名为ipals_wsgi
。要么重命名文件,要么更改命令:但更可取的是,恢复到Django的默认应用程序布局——我怀疑,即使你修复了当前的问题,你也会遇到找不到设置的问题,这在默认情况下是不会发生的。