在WebFaction上部署简单的Flask应用
我按照 "无法在Webfaction上部署简单的Flask应用" 中的说明,设置了一个示例测试应用,以便让一个基本的网页应用运行起来。
下面是代码片段和结构:
"在Webfaction服务器上"
/home/<user>/webapps
ls
>> testapp ( <-- my testapp)
cd testapp
>> apache2 htdocs
cd htdocs
>> index.py testapp.py
我存放在htdocs下的index.py文件如下:
import sys
testapp = "/home/<user>/webapps/testapp/htdocs"
if not testapp in sys.path:
sys.path.insert(0, testapp)
from testapp import app as application
我存放在htdocs下的testapp.py文件如下:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
app.run()
我存放在/home//webapps/testapp/apache2/conf下的httpd.conf文件如下:
ServerRoot "/home/<user>/webapps/testapp/apache2"
LoadModule dir_module modules/mod_dir.so
LoadModule env_module modules/mod_env.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module modules/mod_mime.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule wsgi_module modules/mod_wsgi.so
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User- Agent}i\"" combined
CustomLog /home/<user>/logs/user/access_testapp.log combined
DirectoryIndex index.py
DocumentRoot /home/<user>/webapps/testapp/htdocs
ErrorLog /home/<user>/logs/user/error_testapp.log
KeepAlive Off
Listen 24329
MaxSpareThreads 3
MinSpareThreads 1
ServerLimit 1
SetEnvIf X-Forwarded-SSL on HTTPS=1
ThreadsPerChild 5
WSGIDaemonProcess testapp processes=5 python-path=/home/<user>/webapps/testapp /lib/python3.1 threads=1
WSGIProcessGroup testapp
WSGIRestrictEmbedded On
WSGILazyInitialization On
WSGIPythonPath /home/<user>/webapps/testapp/htdocs
WSGIScriptAlias / /home/<user>/webapps/testapp/htdocs/index.py
<Directory /home/<user>/webapps/testapp/htdocs>
AddHandler wsgi-script .py
ReWriteEngine on
RewriteBase /
WSGIScriptReloading On
</Directory>
我的域名已经指向了Webfaction上的项目。在我按照说明用新的index.py覆盖之前,默认的index.py是可以正常工作的。
以下是我在Webfaction控制面板中应用的详细信息:
testapp
Name testapp
Label mod_wsgi 3.4/Python 3.2
Machine
Web377
Description
mod_wsgi 3.4/Python 3.2
Port 24329
我查看了用户下的error_testapp.log,内容如下:
[Mon Feb 04 07:45:05 2013] [notice] caught SIGTERM, shutting down
[Mon Feb 04 07:45:10 2013] [notice] Apache/2.2.17 (Unix) mod_wsgi/3.4 Python/3.2.3 configured -- resuming normal operations
[Mon Feb 04 07:57:14 2013] [notice] caught SIGTERM, shutting down
[Mon Feb 04 07:57:19 2013] [notice] Apache/2.2.17 (Unix) mod_wsgi/3.4 Python/3.2.3 configured -- resuming normal operations
当我尝试从 http:// <user>.webfactional.com/testapp/ 启动应用时,
我收到了“网站未配置”的消息。
有人能告诉我这里可能出什么问题吗?这是我第一次使用Flask和Webfaction。提前感谢你的时间。如果你需要更多细节,请告诉我。