如何在AWS EC2上部署flask应用程序 - 内部服务器错误?
我想在AWS EC2上部署flask应用程序。但是我遇到了500内部服务器错误。如何在AWS EC2上部署flask应用程序 - 内部服务器错误?
首先,我已经安装了apache webserver和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>
最后,我重新启动apache2。
$ sudo apachectl restart
当我去AWS EC2域,我得到了一个500内部服务器错误。
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at [email protected] 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.
我的flaskapp应该在python3上运行。
我不知道如何处理这个问题。
相似问题的类型是answered before。
从答案引用:
的问题本质上是要安装瓶,以及其他可能的所需的库,在虚拟环境中,但蟒蛇(WSGI接口)与系统蟒蛇这确实运行没有安装这些额外的库。
显然,处理此问题的一种方法是使用
site
软件包将site-packages
从您的venv添加到执行的Python。这将在您的.wsgi
文件中进行。
import site
site.addsitedir('/path/to/your/venv/lib/pythonX.X/site-packages')
不建议直接添加“site-packages''目录。请参阅关于如何使用虚拟环境的mod_wsgi文档。 http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html –
感谢您的好阅读@GrahamDumpleton –
你有没有看你的Django应用程序日志或Apache日志,这或许是在'/无功/日志/ apache'或'/无功/日志/ httpd'? – birryree
感谢您的回复。 '/ var/log/apache2/error.log'中没有任何内容。 '/ var/log'目录中没有httpd目录。 –
这可能表明问题来自'wsgi'模块,并且由于Apache默认为“警告”级日志记录,所以它会抑制日志输出。尝试在你的'httpd.conf'中设置'LogLevel info'来在日志中显示更多的消息。 – birryree