【问题标题】:Problems deploying Flask on Bluehost在 Bluehost 上部署 Flask 的问题
【发布时间】:2014-04-22 20:15:12
【问题描述】:

我一直在阅读指南here,但我无法在 Bluehost 上部署 Flask。

这里是安装在 venv 中的包:

Flask           - 0.10.1       - active 
Jinja2          - 2.7.2        - active 
MarkupSafe      - 0.21         - active 
Python          - 2.7.3        - non-active development (/usr/local/lib/python2.7/lib-dynload)
Python          - 2.7.6        - active development (/usr/local/lib/python2.7/lib-dynload)
Werkzeug        - 0.9.4        - active 
flup            - 1.0.2        - active 
itsdangerous    - 0.24         - active 
pip 1.5.4 has no metadata
setuptools 2.2 has no metadata
wsgiref         - 0.1.2        - active development (/usr/local/lib/python2.7)
yolk            - 0.4.3        - active

我在 public_html 中的 .htaccess 文件:

Options +ExecCGI
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ flask_hello_world.fcgi/$1 [QSA,L]

flask_hello_world.fcgi,也在public_html中:

    #!/home/REDACTED/venv/flask_hello_world/bin/python

    from flup.server.fcgi import WSGIServer
    from flask_hello_world_app import app as application

    WSGIServer(application).run()

flask_hello_world_app.py 文件,也在 public_html 中:

from datetime import datetime
from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!'

@app.route('/the-time')
def the_time():
     cur_time = str(datetime.now())
     return cur_time + ' is the current time!  ...YEAH!'

if __name__ == '__main__':
    app.run()

执行flask_hello_world.fcgi时输出如下:

WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
Status: 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 12

Hello World!Unhandled exception in thread started by 
sys.excepthook is missing
lost sys.stderr
Unhandled exception in thread started by 
sys.excepthook is missing
lost sys.stderr
Unhandled exception in thread started by 
sys.excepthook is missing
lost sys.stderr
Unhandled exception in thread started by 
sys.excepthook is missing
lost sys.stderr
Unhandled exception in thread started by 
sys.excepthook is missing
lost sys.stderr

用python解释器执行flask_hello_world.fcgi时输出如下:

  Traceback (most recent call last):
  File "flask_hello_world.fcgi", line 4, in <module>
    from flask_hello_world_app import app as application
  File "/home/REDACTED/public_html/flask_hello_world/flask_hello_world_app.py", line 2, in <module>
    from flask import Flask
  File "/usr/lib/python2.6/site-packages/flask/__init__.py", line 19, in <module>
    from jinja2 import Markup, escape
ImportError: No module named jinja2

Apache错误日志如下:

[Tue Apr 22 19:56:19 2014] [warn] [client xxx] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
[Tue Apr 22 19:56:19 2014] [error] [client xxx] Premature end of script headers: flask_hello_world.fcgi
[Tue Apr 22 19:56:19 2014] [error] [client xxx] exec used but not allowed in /home/REDACTED/public_html/500.shtml

我过去已经成功部署过 Flask,所以我现在有点不知所措。我想我遗漏了一些简单的东西,如果有任何帮助,我们将不胜感激。


编辑:这是我在检查 suexec 日志时发现的权限/所有权问题。

【问题讨论】:

    标签: python apache flask bluehost


    【解决方案1】:

    除了明显的是 Jinja2 真的安装了,我敢打赌你的 mod_wsgi 没有找到你的 virtualenv。这可以解释 Jinja2 环境错误。

    mod_wsgi(Apache) deployment doc的最底部

    如果你想使用带有 mod_wsgi 的虚拟环境,你必须 稍微修改你的 .wsgi 文件。

    将以下行添加到 .wsgi 文件的顶部:

    activate_this = '/path/to/env/bin/activate_this.py'

    execfile(activate_this, dict(file=activate_this))

    这设置了 根据虚拟环境的设置加载路径。 保持 请记住,路径必须是绝对的。

    【讨论】:

    • 感谢您的回复。这部分是 venv 问题,特别是由于权限问题而访问它。
    猜你喜欢
    • 1970-01-01
    • 2015-07-11
    • 1970-01-01
    • 1970-01-01
    • 2018-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-24
    相关资源
    最近更新 更多