无法在Webfaction上部署简单的Flask应用程序
问题描述:
我一直在试图让Flask在我的webfaction服务器上工作几个小时而没有任何结果。无法在Webfaction上部署简单的Flask应用程序
我按照说明在http://flask.pocoo.org/snippets/65/
我下的htdocs我index.py文件存储。
import sys
yourappname = "/home/<myusername>/webapps/myapp/htdocs"
if not yourappname in sys.path:
sys.path.insert(0, yourappname)
from yourappname import app as application
然后,我已经加入这个我的httpd.conf文件:
WSGIPythonPath /home/yourusername/webapps/yourapp/htdocs/
#If you do not specify the following directive the app *will* work but you will
#see index.py in the path of all URLs
WSGIScriptAlias//home/yourusername/webapps/yourapp/htdocs/index.py
<Directory /home/yourusername/webapps/yourapp/htdocs/>
AddHandler wsgi-script .py
RewriteEngine on
RewriteBase/
WSGIScriptReloading On
</Directory>
然后我有myapp.py在同一htdocs目录旁边index.py:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
app.run()
我有我的域名在webfaction指向我的项目。按照说明中的说明,默认的index.py在我之前覆盖新的index.py。但是,我只能得到服务器500.我很抱歉,但在Linux和管理服务器方面,我是一个完全noob。我甚至无法访问用户下的错误日志,因为它表示我没有权限。
我认为它与我在linux服务器上安装烧瓶有关,我通过简单的安装来安装它,它说它安装了所有的依赖关系,并没有给出任何错误。
答
一对夫妇的建议:
- 你不应该有MYAPP无处不在,你有yourappname在index.py?
- 另外,我假设你已经在'做适当的替换WSGIPythonPath /首页/ yourusername/webapps /下yourapp/htdocs目录
- 您是否尝试过通过发行
~/webapps/<app_name>/apache2/bin/restart
你真的应该重新启动Apache服务器考虑使用mod_wsgi的守护进程模式,而不是嵌入式解释器。在您的文档根目录中放置任何Python代码也没有什么好的理由。 – ThiefMaster 2012-04-14 20:07:19
谢谢,我会研究mod_wsgi的守护进程模式。我也会将我的python代码移出文档根目录。 – 2012-04-14 20:59:58