【发布时间】:2017-11-23 11:53:47
【问题描述】:
我在尝试在 Amazon EC2 服务器上部署我的 Flask 应用程序时遇到问题。
我遵循了here 和here as well 的教程。
当我运行我的服务器时,在执行sudo apachect1 restart 之后,我在导航到我的 ec2 站点时收到 500 内部错误。检查日志我收到以下错误。
[Tue Jun 20 19:10:48.429468 2017] [wsgi:error] ImportError: No module named flask, referer: http://ec2-<MY-EC2-URL>.amazonaws.com/
尽管如此,通过我用来访问 EC2 实例的 PuTTY,我可以看到 Python 和 flask 已安装...
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import flask
>>> flask.__version__
'0.12.2'
我认为/阅读可能是找不到我的 Python 路径的问题。所以我在我的apache配置文件中添加了python-path=/usr/lib/python2.7....
000-default.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
WSGIDaemonProcess leu threads=5 python-path=/usr/lib/python2.7
WSGIScriptAlias / /var/www/html/leu/app.wsgi
<Directory leu>
WSGIProcessGroup leu
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
仍然没有运气。我见过很多设置虚拟环境的方法,但我还没有这样做。我最初使用 Python 3.5 在 PyCharm 中创建了项目,但后来我返回项目设置并使用 Python 2.7 创建它并添加了所有相应的导入。当我这样做时仍然没有运气。
我应该用 virtualenv 重新启动吗?设置 Apache 时我缺少什么吗?
app.wsgi
import sys
sys.path.insert(0, 'var/www/html/leu')
from app import app as application
有什么帮助吗?
编辑:
还尝试将我上面的 Apache 配置文件中的 Python 路径更改为 /usr/local/lib/python2.7 但仍然没有运气
【问题讨论】:
-
我认为第一步是确保您可以在本地访问服务器。 localhost:<port> 在 EC2 上。然后在尝试从浏览器访问它时检查该 EC2 实例的传入端口设置是否打开
标签: python apache python-2.7 amazon-web-services amazon-ec2