【发布时间】:2015-11-24 19:28:28
【问题描述】:
我正在尝试在 Apache 共享托管服务器中部署一个简单的烧瓶应用程序。
我不确定这里出了什么问题。
我现在卡在.cgi 文件中。
烧瓶应用 - hello.py:
#!/usr/bin/python
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!\n"
if __name__ == "__main__":
app.run()
myapp.cgi 文件:
#!/usr/bin/python
import os
from wsgiref.handlers import CGIHandler
from hello import app
os.environ['SERVER_NAME'] = '127.0.0.1'
os.environ['SERVER_PORT'] = '5000'
os.environ['REQUEST_METHOD'] = 'GET'
os.environ['PATH_INFO'] = ""
CGIHandler().run(app)
这两个文件都放在/home/username/public_html/cgi-bin目录下
同样的cgi-bin 有一个名为myenv 的目录——这是我创建的virtualenv。 virtualenv 处于活动状态。
现在,
我导航到 cgi-bin 目录并运行 -
python hello.py
我明白了:
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
所以这很好。现在我正在运行 myapp.cgi 文件:
python myapp.cgi
我明白了:
Status: 301 MOVED PERMANENTLY
Content-Type: text/html; charset=utf-8
Content-Length: 251
Location: http://127.0.0.1:5000/
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>Redirecting...</title>
<h1>Redirecting...</h1>
<p>You should be redirected automatically to target URL: <a href="http://127.0.0.1:5000/">http://127.0.0.1:5000/</a>. If not click the link.
我怎样才能使这个状态为 200 OK, 请提出建议。
谢谢!
【问题讨论】:
-
@Burhan:你能建议我吗?
标签: python apache deployment flask cgi