2017-06-21 71 views
1

我已经搜索,尝试和运行几乎所有的教程可用来运行我的Django应用程序与Apache或甚至Nginx(其中大部分是3岁或4岁以上)。Django WSGI没有模块名为'站点'

我已经成功完成了所有与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 应用= get_wsgi_application()

我也尝试用默认wsgi.py无济于事运行它。 至于项目的其余部分,它只是一个全新的django项目,除了将虚拟环境放入/var/www/shinra/env/shinra/bin之外,没有其他任何修改。谢谢,我一直在与此战斗一段时间,而我是django的新手。使用apache2运行这个显然会在apache日志中产生相同的错误。

编辑:这也将是很好的一提的是,我试图在亚马逊网络服务运行此EC2实例

UPDATE:

我尝试使用gunicorn尽一切从头开始再次,到目前为止,它的工作原理,如果IM在我的虚拟环境和运行

/home/ubuntu/venvs/shinra/bin/gunicorn -c /home/ubuntu/shinra/scripts/gunicorn_config.py shinra.wsgi 

但如果我设置,使用主管我得到这个错误:

[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

你不能直接用Python直接运行''wsgi.py''。对于Apache而言,Django指令位于https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/modwsgi/在你的问题中没有任何东西可以建议你设置了什么,所以不可能给出任何指导什么可能不适用于Apache。 –

回答

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 
相关问题