在共享Web主机上安装Flask

时间:2014-11-29 04:51:58

标签: python flask

我可以运行“./flaskcgi.cgi”,但我无法在浏览器上运行(domain.com/testing/)。我只收到500内部服务器错误。这两个python文件是带有chmod的“+ x”。

flaskapp.py(在/ scgi-bin /.):

#!/home/NAME/public_html/cgi-bin/flask/bin/python

from flask import Flask
app = Flask(__name__)
app.config['DEBUG'] = True
app.config['APPLICATION_ROOT'] = '/testing'

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

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

flaskcgi.cgi(在/ scgi-bin /.):

#!/home/NAME/public_html/cgi-bin/flask/bin/python

import os, sys
import cgitb; cgitb.enable()
from wsgiref.handlers import CGIHandler

os.environ['SERVER_NAME'] = '127.0.0.1'
os.environ['SERVER_PORT'] = '5000'
os.environ['REQUEST_METHOD'] = 'GET'
os.environ['PATH_INFO'] = ""

log = open('log.txt', 'a')
log.write("____\n")
log.flush()

app = None
try:
    from flaskapp import app
    CGIHandler().run(app)
except Exception, e:
    log.write(str(e) + "\n")

.htaccess(in / testing /.):

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /home/NAME/public_html/scgi-bin/flaskcgi.cgi/$1 [L]

更新1 - 我终于可以执行/测试但是我无法获得正确的请求路径。

新的www / .htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^testing/(.*)$ /home/NAME/public_html/scgi-bin/flaskcgi.cgi/$1 [L]

然而,当我去https://domain.com/testing/about?a=1时,我得到:

request.path: /
request.url: https://domain.com/scgi-bin/flaskcgi.cgi/?a=1
request.script_root: /scgi-bin/flaskcgi.cgi.

我期待/ about?a = 1 as request.path。

0 个答案:

没有答案