gpt4 book ai didi

django - mod_wsgi : Exception occurred processing WSGI script (django deployment)

转载 作者:行者123 更新时间:2023-12-04 13:22:18 25 4
gpt4 key购买 nike

我正在尝试使用以下 Apache 配置部署 django 项目:

Apache 虚拟主机配置

<Virtualhost *:80>
DocumentRoot /var/www/project/backend
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

WSGIDaemonProcess backend python-home=/var/www/project/myenv python-path=/var/www/gestor_documental/backend

WSGIProcessGroup backend
WSGIScriptAlias / /var/www/project/backend/backend/wsgi.py process-group=backend
Alias /static/ /var/www/project/backend/static/

<Directory /var/www/project/backend>
Require all granted
</Directory>
</Virtualhost>

wsgi.load 文件
LoadModule wsgi_module "/var/www/project/myenv/lib/python3.5/site-packages/mod_wsgi/server/mod_wsgi-py35.cpython-35m-x86_64-linux-gnu.so"
WSGIPythonHome "/var/www/project/myenv"

wsgi.py 是 django 默认自带的

wsgi.py
import os
from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings")

application = get_wsgi_application()

这是项目树:
project
|- backend
| |- api (django app)
| |- backend
| |- ...
| |- settings.py
| |- wsgi.py
|-- myenv (virtualenv)

这是我尝试加载 Web 时不断收到的错误日志:
mod_wsgi (pid=38953): Failed to exec Python script file '/var/www/project/backend/backend/wsgi.py'.
mod_wsgi (pid=38953): Exception occurred processing WSGI script '/var/www/project/backend/backend/wsgi.py'.
Traceback (most recent call last):
File "/var/www/project/backend/backend/wsgi.py", line 16, in <module>
application = get_wsgi_application()
File "/var/www/project/myenv/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup(set_prefix=False)
File "/var/www/project/myenv/lib/python3.5/site-packages/django/__init__.py", line 22, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/var/www/project/myenv/lib/python3.5/site-packages/django/conf/__init__.py", line 53, in __getattr__
self._setup(name)
File "/var/www/project/myenv/lib/python3.5/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/var/www/project/myenv/lib/python3.5/site-packages/django/conf/__init__.py", line 97, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/var/www/project/myenv/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 'backend'

我遵循了每个教程并尝试了大量配置,但仍然遇到相同的错误。

我正在使用 python 3.5.2 在 virtualenv 和 中Apache 2.4.18

我已经通过 pip3 安装了 mod_wsgi。

有人可以帮我解决这个问题并告诉我我做错了什么吗?

谢谢你。

最佳答案

我解决了它改变 wsgi.py文件添加下一行:

import sys

sys.path.append('/var/www/project/backend')

我不知道这是否是正确答案,但它实际上适用于这种解决方法。

关于django - mod_wsgi : Exception occurred processing WSGI script (django deployment),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49300999/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com