【发布时间】:2017-01-22 18:25:17
【问题描述】:
我正在准备设置 Apache/2.2.22 (Debian) mod_wsgi/3.3 Python/2.7.3
我设法执行了 WSGIScriptAlias,但只执行了顶级模块代码,而不是其中定义的 application。
Apache 配置:
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
WSGIScriptAlias /testurl /home/django/test/test/wsgi_test.py
<Directory /home/django/test/test>
<Files wsgi_test.py>
Order deny,allow
Allow from all
</Files>
</Directory>
wsgi_test.py:
#!/usr/bin/python
import sys
print >> sys.stderr, "I'm wsgi_test"
def application(environ, start_response):
print >> sys.stderr, 'in application'
status = '200 OK'
output = 'hello World'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
当使用浏览器请求 url 时,wsgi_test.py 脚本被执行(“我是 wsgi_test”出现在 apache 错误日志中)。但是,没有提供页面(500 内部服务器错误),并且还有一个额外的错误日志条目脚本头的过早结束:wsgi_test.py。
作为第二个测试,我使用了一个简单的脚本,它正确地服务于“Hello World”:
wsgi_test2.py:
#!/usr/bin/python
import sys
print 'Content-type: text/plain\n\n'
print 'Hello World'
我的问题: mod_wsgi 如何知道并执行应用程序?
通过以上测试,我得出结论wsgi_test.py 会立即执行。由于没有可执行代码,只有application 的定义,因此脚本不会输出任何内容,因此服务器会抱怨缺少 html 标头。如何告诉系统运行application?
【问题讨论】: