使用 apache

问题描述

我正在尝试使用 apache 在亚马逊 Lightsail 中部署我的 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",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()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...