python - 使用 apache 在 aws lightsail 上部署 django
问题描述
我正在尝试使用 apache 在 amazon lightail 中部署我的 django 项目。
我现在收到 500 内部服务器错误,日志文件说我缺少 django。这是错误日志:
[Fri Jun 18 09:17:21.185206 2021] [mpm_event:notice] [pid 18855:tid 139805003744384] AH00491: caught SIGTERM, shutting down
[Fri Jun 18 09:17:21.234245 2021] [mpm_event:notice] [pid 32187:tid 139822253159552] AH00489: Apache/2.4.38 (Debian) mod_wsgi/4.6.5 Python/3.7 configured -- resuming norma
l operations
[Fri Jun 18 09:17:21.234333 2021] [core:notice] [pid 32187:tid 139822253159552] AH00094: Command line: '/usr/sbin/apache2'
[Fri Jun 18 09:17:58.402513 2021] [wsgi:error] [pid 32188:tid 139822222972672] [remote 93.43.210.55:49401] mod_wsgi (pid=32188): Failed to exec Python script file '/var/ww
w/sito_fotografo/sito_fotografo/sito/wsgi.py'.
[Fri Jun 18 09:17:58.402562 2021] [wsgi:error] [pid 32188:tid 139822222972672] [remote 93.43.210.55:49401] mod_wsgi (pid=32188): Exception occurred processing WSGI script
'/var/www/sito_fotografo/sito_fotografo/sito/wsgi.py'.
[Fri Jun 18 09:17:58.402710 2021] [wsgi:error] [pid 32188:tid 139822222972672] [remote 93.43.210.55:49401] Traceback (most recent call last):
[Fri Jun 18 09:17:58.402734 2021] [wsgi:error] [pid 32188:tid 139822222972672] [remote 93.43.210.55:49401] File "/var/www/sito_fotografo/sito_fotografo/sito/wsgi.py", li
ne 12, in <module>
[Fri Jun 18 09:17:58.402777 2021] [wsgi:error] [pid 32188:tid 139822222972672] [remote 93.43.210.55:49401] from django.core.wsgi import get_wsgi_application
[Fri Jun 18 09:17:58.402796 2021] [wsgi:error] [pid 32188:tid 139822222972672] [remote 93.43.210.55:49401] ModuleNotFoundError: No module named 'django'
[Fri Jun 18 09:23:28.841563 2021] [wsgi:error] [pid 32188:tid 139822105474816] [remote 93.43.210.55:49231] mod_wsgi (pid=32188): Failed to exec Python script file '/var/ww
w/sito_fotografo/sito_fotografo/sito/wsgi.py'.
[Fri Jun 18 09:23:28.841622 2021] [wsgi:error] [pid 32188:tid 139822105474816] [remote 93.43.210.55:49231] mod_wsgi (pid=32188): Exception occurred processing WSGI script
'/var/www/sito_fotografo/sito_fotografo/sito/wsgi.py'.
[Fri Jun 18 09:23:28.841707 2021] [wsgi:error] [pid 32188:tid 139822105474816] [remote 93.43.210.55:49231] Traceback (most recent call last):
[Fri Jun 18 09:23:28.841750 2021] [wsgi:error] [pid 32188:tid 139822105474816] [remote 93.43.210.55:49231] File "/var/www/sito_fotografo/sito_fotografo/sito/wsgi.py", li
ne 12, in <module>
[Fri Jun 18 09:23:28.841758 2021] [wsgi:error] [pid 32188:tid 139822105474816] [remote 93.43.210.55:49231] from django.core.wsgi import get_wsgi_application
[Fri Jun 18 09:23:28.841775 2021] [wsgi:error] [pid 32188:tid 139822105474816] [remote 93.43.210.55:49231] ModuleNotFoundError: No module named 'django'
如果我尝试打电话:
which python3
我明白了
/opt/bitnami/python/bin/python3
我真的不知道如何使用这些信息。我在重新安装 apache 后将我的项目放在 /var/www 中,创建实例后我在服务器中找到的版本有一些我不喜欢的非常奇怪的文件配置。在 var/www/myproject 里面有一个虚拟环境,我在其中安装了我的项目所需的模块
这是我在项目中的 wsgi.py 文件的相关部分
Alias /static /var/www/sito_fotografo/sito_fotografo/static
<Directory /var/www/sito_fotografo/sito_fotografo/static>
Require all granted
</Directory>
Alias /media /var/www/sito_fotografo/sito_fotografo/media
<Directory /var/www/sito_fotografo/sito_fotografo/media>
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory /usr/share/>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/sito_fotografo/sito_fotografo/sito>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess sito_fotografo python-path=/var/www/sito_fotografo/sito-fotografo/sito python-home=/var/www/sito_fotografo/env
WSGIProcessGroup sito_fotografo
WSGIScriptAlias / /var/www/sito_fotografo/sito_fotografo/sito/wsgi.py
这是我的 wsgi 文件:
"""
WSGI config for sito project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
sys.path.append('var/www/sito_fotografo/sito_fotografo/sito')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sito.settings')
application = get_wsgi_application()
解决方案
推荐阅读
- reactjs - 如何使用带有 Firestore 数据的反应挂钩从索引链接到显示视图
- shell - 复合变量可以用作ksh中的函数参数吗?
- angular - 尝试使用 Angular 材质时出错
- valueerror - ValueError:无法读取 cfg 文件(sense2vec、reddit 向量)
- python - 熊猫:将数据连接到单行到新列
- c++ - 如何将“void (MyClass::*)(int)”转换为“void (*)(int)”?
- python - 音频信号的信噪比计算
- python - 图像的 Python pyinstaller 可执行问题
- sql-server - 如何根据 T-SQL (SSMS 2017) 中下一条记录的 [EffectiveDate]-1 计算到期日期?
- c# - 来自 InlineKeyboardMarkup 和 InlineKeyboardButton 的错误