我一直在尝试使用nginx和gunicorn部署django,目前正在发布一个问题,我遵循了建议的on SO并且我已尝试this way的建议,建议使用gunicorn docs但仍然没有工作......
(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()
答案 0 :(得分:0)
我不确定为什么您有一个名为ipals_wsgi.py
的文件,并且它似乎位于项目的顶层或您的设置文件所在的位置。通常,Django的startproject
命令会创建一个与项目同名的子目录,并在该子目录中放置一个名为wsgi.py
的文件和settings.py
。你似乎修改了它,但我无法理解为什么。
在任何情况下,调用你的wsgi文件指出问题是什么:你告诉gunicorn查看一个名为ipals
的文件,但是如上所述,该文件被称为{{1} }。重命名文件或更改命令:但更优选的是,恢复到Django的默认应用程序布局 - 我怀疑即使你修复了当前的问题,你也会遇到设置无法找到的问题,这不会#39; t默认发生。