我正在通过一个简短的Flask tutorial并且遇到了一些问题。我到最后得到了500 Server错误。如果我从我的虚拟环境中运行.fcgi,我会收到以下消息。我没有看到我有权访问的日志中的任何错误。不确定问题是什么。
错误消息
(flask_hello_world) me@domain [~/public_html/projects/flask_hello_world]# python 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!
的.htaccess
Options +ExecCGI
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %(REQUEST_FILENAME) !-f
RewriteRule ^(.*)$ flask_hello_world.fcgi/$1 [QSA,L]
RewriteLog rewrite.log
RewriteLogLevel 3
flask_hello_world.fcgi
#!/path/to/python27/.virtenv/flask_hello_world/bin/python
from flup.server.fcgi import WSGIServer
from flask_hello_world_app import app as application
if __name__ == '__main__':
WSGIServer(application).run()
flask_hello_world_app.py
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()
已安装在/.virtenv/flask_hello_world
# pip list
Flask (0.10.1)
flup (1.0.2)
itsdangerous (0.23)
Jinja2 (2.7.1)
MarkupSafe (0.18)
pip (1.4.1)
setuptools (0.9.8)
Werkzeug (0.9.4)
wsgiref (0.1.2)
答案 0 :(得分:1)
实际上有两个问题引起了我的问题。
我在RewriteCond
中使用括号而不是花括号
我的.htaccess
文件。该网站帮助指出了这一点。
http://www.lyxx.com/freestuff/002.html
flask_hello_world.fcgi
中的shebang不正确。解决.htaccess
问题后,我仍然收到内部服务器错误。访问
flask_hello_world.fcgi
文件直接给了我指出路径的错误
问题。