我已经搜索过,尝试并运行了几乎所有可用的教程来运行我的django应用程序,使用apache甚至nginx(大多数都超过3或4年)。
我已经设法通过并获取所有部分内容与nginx一起使用,直到我放弃,现在我正在尝试使用apache2,到目前为止我唯一的错误是使用wsgi.py,其他一切正常很好,但正在运行
sudo python3 -i /var/www/shinra/shinra/wsgi.py
给了我以下错误:
Traceback (most recent call last):
File "/var/www/shinra/shinra/wsgi.py", line 23, in <module>
application = get_wsgi_application()
File "/home/ubuntu/.local/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup(set_prefix=False)
File "/home/ubuntu/.local/lib/python3.5/site-packages/django/__init__.py", line 22, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/home/ubuntu/.local/lib/python3.5/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/home/ubuntu/.local/lib/python3.5/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/home/ubuntu/.local/lib/python3.5/site-packages/django/conf/__init__.py", line 110, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
ImportError: No module named 'shinra'
我的wsgi.py设置如下:
import os
import sys
PROJECT_DIR = '/var/www/shinra'
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "shinra.settings")
def execfile(filename):
globals = dict( __file__ = filename )
exec( open(filename).read(), globals )
activate_this = os.path.join( PROJECT_DIR, 'env/shinra/bin', 'activate_this.py' )
execfile( activate_this )
来自django.core.wsgi导入get_wsgi_application application = get_wsgi_application()
我也尝试使用默认的wsgi.py运行它无济于事。
至于项目的其余部分,它只是一个全新的django项目,除了将虚拟环境置于/var/www/shinra/env/shinra/bin
之外,其他任何内容都没有被修改过。谢谢你,我一直在和这个战斗,我是django的新手。使用apache2运行它显然会在apache日志中产生相同的错误。
编辑:我还想提一下,我正试图在亚马逊网络服务EC2实例中运行此功能
更新
我尝试再次使用gunicorn从头开始做任何事情,到目前为止,如果我在我的虚拟环境中运行
/home/ubuntu/venvs/shinra/bin/gunicorn -c /home/ubuntu/shinra/scripts/gunicorn_config.py shinra.wsgi
但如果我使用supervisor设置它,我会收到此错误:
[2017-06-21 05:15:25 +0000] [10320] [INFO] Starting gunicorn 19.7.1
[2017-06-21 05:15:25 +0000] [10320] [INFO] Listening at: http://0.0.0.0:8000 (10320)
[2017-06-21 05:15:25 +0000] [10320] [INFO] Using worker: sync
[2017-06-21 05:15:25 +0000] [10323] [INFO] Booting worker with pid: 10323
[2017-06-21 05:15:25 +0000] [10323] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/home/ubuntu/venvs/shinra/lib/python3.5/site-packages/gunicorn/arbiter.py", line 578, in spawn_worker
worker.init_process()
File "/home/ubuntu/venvs/shinra/lib/python3.5/site-packages/gunicorn/workers/base.py", line 126, in init_process
self.load_wsgi()
File "/home/ubuntu/venvs/shinra/lib/python3.5/site-packages/gunicorn/workers/base.py", line 135, in load_wsgi
self.wsgi = self.app.wsgi()
File "/home/ubuntu/venvs/shinra/lib/python3.5/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/home/ubuntu/venvs/shinra/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/home/ubuntu/venvs/shinra/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/home/ubuntu/venvs/shinra/lib/python3.5/site-packages/gunicorn/util.py", line 352, in import_app
__import__(module)
ImportError: No module named 'shinra'
[2017-06-21 05:15:25 +0000] [10323] [INFO] Worker exiting (pid: 10323)
[2017-06-21 05:15:25 +0000] [10320] [INFO] Shutting down: Master
[2017-06-21 05:15:25 +0000] [10320] [INFO] Reason: Worker failed to boot.
gunicorn配置文件是:
command = '/home/ubuntu/venvs/shinra/bin/gunicorn'
pythonpath = '/home/ubuntu/venvs/shinra/bin/python'
bind = '0.0.0.0:8000'
workers = 3
答案 0 :(得分:1)
我终于明白了!我对主管的配置缺少一些参数:
[program:shinra_gunicorn]
command=/home/ubuntu/venvs/shinra/bin/gunicorn -c /home/ubuntu/shinra/gunicorn_config.py shinra.wsgi
directory=/home/ubuntu/shinra
environment=PATH="/home/ubuntu/venvs/shinra/bin"
autostart=true
autorestart=true
stderr_logfile=/var/log/shinra.err.log
stdout_logfile=/var/log/shinra.out.log