Python 如何在AWS EC2上部署flask应用程序-内部服务器错误?

Python 如何在AWS EC2上部署flask应用程序-内部服务器错误?,python,apache,amazon-web-services,amazon-ec2,mod-wsgi,Python,Apache,Amazon Web Services,Amazon Ec2,Mod Wsgi,我想在AWS EC2上部署flask应用程序。但是我遇到了500内部服务器错误 The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator at webmaster@localhost to inform them of the time this error occurr

我想在AWS EC2上部署flask应用程序。但是我遇到了500内部服务器错误

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at webmaster@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.
首先,我安装了apachewebserver和mod_wsgi

$ sudo apt-get update
$ sudo apt-get install apache2
$ sudo apt-get install libapache2-mod-wsgi
$ sudo apt-get install libapache2-mod-wsgi-py2
我已经安装了pip3和烧瓶

$ sudo apt-get install python3-pip
$ sudo pip3 install flask
这是flaskapp目录中的flask.wsgi文件

import sys
sys.path.insert(0, '/var/www/html/flaskapp')

from flaskapp  import app as application
我已经启用了mod_wsgi

WSGIDaemonProcess flaskapp threads=5
WSGIScriptAlias / /var/www/html/flaskapp/flaskapp.wsgi

<Directory flaskapp>
    WSGIProcessGroup flaskapp
    WSGIApplicationGroup %{GLOBAL}
    Order deny,allow
    Allow from all
</Directory>
当我转到AWS EC2域时,我得到一个500内部服务器错误

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at webmaster@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.
我的烧瓶应用程序应该在python3上运行


我不知道如何处理这个问题。

类似的问题也曾出现过

引述答覆:

问题本质上是,您正在虚拟环境中安装Flask,以及可能需要的其他库,但是python(wsgi接口)运行的系统python没有安装这些额外的库

显然,处理这个问题的一种方法是使用
site
包将venv中的
site包添加到执行的Python中。这将放在您的
.wsgi
文件中


您是否查看了django应用程序日志或Apache日志,这些日志可能位于
/var/log/Apache
/var/log/httpd
中?谢谢您的回复。
/var/log/apache2/error.log
中没有任何内容。在
/var/log
目录中没有httpd目录。这可能表明问题来自
wsgi
模块,它正在抑制日志输出,因为Apache默认为
warn
级别日志记录。尝试在
httpd.conf
中设置
LogLevel info
,以在日志中显示更多消息。不建议直接添加
站点包
目录。有关如何使用虚拟环境,请参阅mod_wsgi文档。
import site

site.addsitedir('/path/to/your/venv/lib/pythonX.X/site-packages')