【发布时间】:2018-11-09 19:56:41
【问题描述】:
我成功地使用 Python 3.6、Apache 和 mod_wsgi 配置了 Ubuntu 16.04 LTS 机器。这个文件夹有一个安装了 Flask 的 virtualenv。
$ ls -l /var/www/html/odb/
bin/
lib/
include/
config.wsgi
.wsgi 文件非常简单,Apache conf 也是如此:
$ cat /var/www/html/odb/config.wsgi
activate_this = '/home/ubuntu/odb/bin/activate_this.py'
with open(activate_this) as file_:
exec(file_.read(), dict(__file__=activate_this))
import sys
sys.path.insert(0, '/var/www/html/odb/')
def application(environ,start_response):
start_response('200 OK',[('Content-type','text/html')])
return ['Hello world']
$ cat /etc/apache2/sites-available/odb.conf
<VirtualHost *>
ServerName example.com
WSGIDaemonProcess webserver threads=5
WSGIScriptAlias / /var/www/html/odb/config.wsgi
<Directory /var/www/html/odb>
WSGIProcessGroup webserver
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
我可以访问虚拟网页。但是当我修改 .wsgi 文件并添加一个 Python Flask 应用程序时,我得到一个 HTTP 500。这是文件:
$ cat /var/www/html/odb/config.wsgi
activate_this = '/home/ubuntu/odb/bin/activate_this.py'
with open(activate_this) as file_:
exec(file_.read(), dict(__file__=activate_this))
import sys
sys.path.insert(0, '/var/www/html/odb/')
from webserver import app as application
$ cat /var/www/html/odb/webserver.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
if __name__ == "__main__":
app.run(debug=True)
当我通过$ flask run --host=0.0.0.0 运行应用程序时,我可以通过互联网访问它,所以我在 .wsgi 文件中指向 Flask 应用程序的方式似乎有问题。我做错了什么?
日志记录:$ cat /var/log/apache2/*log 在 HTTP 500 之后没有给出任何信息。我注意到 /var/www/html/odb/webserver.pyc 出现在 HTTP 500 之后,如果这有帮助的话..?
【问题讨论】:
-
很久没有使用 Apache 为 WSGI 服务了,但是日志可能会给你一个想法。您能否显示相关日志(如果有记忆,它们将在
error.logs) -
感谢您的快速回复。我现在在上面添加了评论。没有可用的日志。